angularjs 頁面跳轉傳遞參數


基於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'
        })

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM