基於ui-router的頁面跳轉傳參
① app.js中
.state('faceWarning',{ url: '/faceWarning', templateUrl: 'pages/face/faceWarning.html', controller: 'WarningCtrl' }) .state('faceWarningList',{ url: '/faceWarningList/:groupId', templateUrl: 'pages/face/faceWarningList.html', controller: 'WarningListCtrl' })
② faceWarning.html中點擊跳轉事件
ng-click="jumpWarningList(data.groupId)"
faceWarning.js中,定義頁面跳轉函數 (使用ui-router的$state.go接口):
faceApp.controller('WarningCtrl', ['$rootScope', '$scope', '$state', function($rootScope, $scope, $state) { $scope.jumpWarningList = function(groupId) { $state.go('faceWarningList', {groupId: groupId}); }; }]);
③ faceWarningList.js,通過ui-router的$stateParams獲取參數groupId
faceApp.controller('WarningCtrl', ['$rootScope', '$scope', '$stateParams', function($rootScope, $scope, $stateParams) { $scope.searchSpecial.groupId = $stateParams.groupId; }]);
這種跳轉,在不傳遞參數時,url: '/faceWarningList/:groupId', 這里將會影響單獨跳轉的實現,導致點擊無效。
如果要實現單獨點擊跳轉(主頁面不帶參數跳轉),需要在app.js中定義參數,不然$state.go在傳輸之后在目標controller接受的時候會被filter過濾掉
.state('faceWarningList',{ url: '/faceWarningList', templateUrl: 'pages/face/faceWarningList.html', params: {'groupId': null}, controller: 'WarningListCtrl' })