国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

javascript - 為什么我無法通過$stateParams在父子State之間傳遞參數?跟State之間的父子關系有關嗎?

瀏覽:171日期:2024-03-07 18:45:39

問題描述

路由設置(兩個State之間有父子關系):

.state('tab.my-profile', { url: '/my/profile', views: { 'tab-my': { templateUrl: 'templates/tab-my-profile.html', controller: 'MyProfileCtrl' } }}) .state('tab.my-profile-mobileinput', { url: '/my/profile/mobileinput', views: { 'tab-my': {params: {'mobile': null}templateUrl: 'templates/util-mobile-input.html',controller: 'MobileInputCtrl', } } })

2.父State的控制器中的代碼:

.controller('MyProfileCtrl', function ($scope, $state) { $scope.goToMobileInput = function () { $state.go('tab.my-profile-mobileinput', {'mobile': '123456'}) };})

3.子State的控制器中的代碼:

.controller('MobileInputCtrl', function ($scope, $stateParams) { alert($stateParams.mobile); // undefined})

能夠跳轉到子State,但在子State的控制器中無法接收到參數(訪問參數時得到的結果是undefined,而非'123456')。看了網上資料這么寫應該無誤,是跟State之間的父子關系有關嗎?

問題解答

回答1:

你的router定義的有問題,params需要和url, views在同一級,views正如字面意思那樣,是指定ui的,你在其中指定了params就有問題了,需要改成如下這樣:

.state('tab.my-profile-mobileinput', { url: '/my/profile/mobileinput', params: {'mobile': null}, views: { 'tab-my': {templateUrl: 'templates/util-mobile-input.html',controller: 'MobileInputCtrl' } } })回答2:

$broadcast,我記得這種應該采用事件廣播,可以將事件從父級作用域傳播至子級作用域,你可以百度一下相關內容,應該能夠解決

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 铅山县| 安宁市| 合作市| 德令哈市| 普宁市| 黄平县| 柞水县| 凤翔县| 肥西县| 盐源县| 高青县| 南漳县| 视频| 宜章县| 景东| 高雄县| 四子王旗| 峨眉山市| 揭阳市| 横峰县| 宝兴县| 湟源县| 武胜县| 阿拉尔市| 泗洪县| 涞源县| SHOW| 巴东县| 长白| 大渡口区| 东至县| 神农架林区| 孝昌县| 南部县| 科技| 克什克腾旗| 普宁市| 天全县| 罗江县| 甘南县| 固阳县|