중첩 된 상태가 있고 상위 및 하위 상태가 별도의 컨트롤러를 가지고 있습니다. 그러나 부모 상태 만 실행됩니다.중첩 상태의 컨트롤러가 실행되지 않습니다.
가 나는 URL 구조를 가지고 : #/레스토랑/2/그래서
, 나는 그것이 '우리의 식품'의 콘텐츠 다음 ID 2와 함께 아이 컨트롤러의 부하를 레스토랑을로드 할 우리의 음식과 다른 기능들을 돌 봅니다.
내 코드는 다음과 같습니다
var app = angular.module("app", ['ui.router']);
app.config(function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise("/");
$stateProvider
.state('home', {
url: '/',
controller: function($scope, $stateParams) {
$scope.setRestaurant(0);
}
})
.state('restaurant', {
url: '/restaurant/:restaurantId',
controller: function($scope, $stateParams, $state) {
console.log('first');
if($stateParams.restaurantId > 0) {
$scope.setRestaurant($stateParams.restaurantId);
}
else {
$state.go('home');
}
}
})
.state('restaurant.our-food', {
url: '/our-food',
templateUrl: 'templates/our-food.html',
controller: function() {
console.log('second');
}
});
});
! 고마워요. 나는 설명서를 읽었으나 그 부분을 놓쳐 버려야한다. –