时间:2020-10-05 21:32:51 | 栏目:JavaScript代码 | 点击:次
首先,你需要已经配置过你的rout,比如:
$stateProvider
.state('firstPage',{
url:'/Page/firstPage',
templateUrl: 'Page/views/firstPage.html',
controller: 'firstPageCtrl'
//dependencies: ['service/vipSeachService']
})
.state('secPage', { params:{'message':null},
url: '/Page/secPage',
templateUrl: 'Page/views/secPage.html',
controller: 'secPageCtrl'
})
其中注意第二个地址信息中的params属性,这个就是你要接受参数的对象,以key :value的形式定义
而在跳转页面时,两个方法都可以传参,一种是直接写在html中
<a ui-sref="sec-page">跳转第二页</a>
此时传参跟在页面地址的后面
<a ui-sref="sec-page({message:messageId})">跳转第二页</a>
第二种就是写在controller中
.controller('firstPageCtrl', function($scope, $state) {
$state.go('secPage'); });
同样参数写在地址后面,以对象的形式
.controller('firstPageCtrl', function($scope, $state) {
$state.go('secPage',{message:messageId});
});
传过去的参数,需要在目标页面的controller中用$stateParams接收,改方法需要提前注入
.controller('secPageCtrl', function($scope, $state,$stateParams) {
var test=$stateParams.message;
});