首先,你需要已经配置过你的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;
});
以上所述是小编给大家介绍的Angular 页面跳转时传参问题,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对phpstudy网站的支持!
本文地址:https://www.stayed.cn/item/14977
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我