【发布时间】:2014-12-04 11:20:21
【问题描述】:
我有两种状态,一种是另一种的孩子。一个代表人员列表 (people),另一个代表当您单击个人以查看更多详细信息时 (people.detail)。
我的第一个状态按预期工作,并且有几个参数代表您可以应用的所有各种服务器端过滤器和分页。子状态是一个模态窗口,它按预期弹出,但我唯一的参数personID 从未进入$stateParams。不知道是不是要结合RESTful风格的URL和查询字符串的风格?
值得注意的是,$stateParams 填充了您对父状态的期望。
编辑:Plunker 表明我的意思 - http://plnkr.co/edit/eNMIEt?p=info(注意 ID 未定义)
app.js
$urlRouterProvider.otherwise('/people');
$stateProvider
.state('people', {
url: '/people?pageNumber&pageSize&sortField&sortDirection&search&countryID&jobFunctionIDs&firmTypeIDs',
templateUrl: 'Static/js/angular/views/people-list.html',
controller: 'PeopleListController',
resolve: {
api: "api",
people: function (api, $stateParams) {
//Code ommitted
},
countries: function (api) {
//Code ommitted
},
jobFunctions: function (api) {
//Code ommitted
},
firmTypes: function (api) {
//Code ommitted
}
}
});
modalStateProvider.state('people.detail', {
url: "/{personID}",
templateUrl: 'Static/js/angular/views/people-detail.html',
controller: function () {
},
resolve: {
person: function (api, $stateParams) {
return api.people.getDetail($stateParams.personID);
}
}
});
modalStateProvider 看起来像:
angular.module('myApp')
.provider('modalState', function ($stateProvider) {
var provider = this;
this.$get = function () {
return provider;
}
this.state = function (stateName, options) {
var modalInstance;
$stateProvider.state(stateName, {
url: options.url,
onEnter: function ($modal, $state) {
modalInstance = $modal.open(options);
modalInstance.result['finally'](function () {
modalInstance = null;
if ($state.$current.name === stateName) {
$state.go('^');
}
});
},
onExit: function () {
if (modalInstance) {
modalInstance.close();
}
}
});
};
})
最后我在控制器中的函数转换到people.detail 状态:
$scope.transitionToPersonDetail = function (personID) {
$state.transitionTo('.detail', { personID: personID }, { location: true, inherit: true, relative: $state.$current, notify: false });
};
【问题讨论】:
标签: javascript angularjs angular-ui-router