AngularJS angular ui router – 将自定义数据传递给控制器
发布时间:2020-12-17 06:55:38 所属栏目:安全 来源:网络整理
导读:以下是我的代码: .state('tab.dash',{ url: '/dash',views: { 'tab-dash': { templateUrl: 'templates/tab1.html',controller: 'QuestionsCtrl' //,resolve: { type: '.net' } } } }) .state('tab.friends',{ url: '/friends',views: { 'tab-friends': { te
以下是我的代码:
.state('tab.dash',{ url: '/dash',views: { 'tab-dash': { templateUrl: 'templates/tab1.html',controller: 'QuestionsCtrl' //,resolve: { type: '.net' } } } }) .state('tab.friends',{ url: '/friends',views: { 'tab-friends': { templateUrl: 'templates/tab1.html',resolve: { type: 'SQL' } } } }) 我想将一个不同的自定义属性传递给上面两个路由,因为它们使用相同的Controller和View,以区分它.我尝试了很多东西.请帮忙怎么做! 解决方法
您可以按如下方式传递自定义数据
.state('tab.dash',data: { customData1: 5,customData2: "blue" },data: { customData1: 6,customData2: "orange" },resolve: { type: 'SQL' } } } }) 在控制器中,您可以按如下方式获取数据值 function QuestionsCtrl($state){ console.log($state.current.data.customData1); console.log($state.current.data.customData2); } 在这里阅读有关此主题的更多信息https://github.com/angular-ui/ui-router/wiki/Nested-States-%26-Nested-Views#inherited-custom-data (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |