5
stateParams의 작동 방식을 이해하는 데 많은 어려움을 겪고 있습니다. 어디에서나 URL /#/manage/456
로 여행 할 때 이 456이되어야하지만 대신 $stateParams
은 빈 개체임을 나타냅니다. 또한 MainCtrl에 전달 된 $state
개체에서 나는 $state.params
을 사용하여 모든 매개 변수에 액세스 할 수 있습니다. 그러나 이것은 바람직하지 않으며 해킹 된 것으로 보입니다. 이 JSFiddle 볼 당신이 잘 작동해야 할 노력하고
angular
.module('router',['ui.router'])
.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider)
{
$stateProvider
.state('manage',
{
url: '/manage',
templateUrl: '/templates/main.html',
controller: 'MainCtrl'
})
.state('manage.item_id',
{
url: '/:item_id',
templateUrl: '/templates/main.html',
controller: 'MainCtrl'
})
}])
.controller('MainCtrl', ['$scope', '$stateParams', '$state', function($scope, $stateParams, $state)
{
// empty object
console.log('$stateParams: ', $stateParams);
// shows the variables i want
console.log('$state.params: ', $state.params);
}])
감사합니다. 내가 잊어 버린 것은로드 된 템플릿에 두 번째'ui-view '지시문을 추가하는 것입니다. – BlinkyTop
데모는 나에게 빈 객체를 사용합니다. – Sami