第一种:
参数会以?的形式出现在访问地址中?:userId会自动变为?userId=0010001
$stateProvider.state('page.home', {
url:"/home?:userId",
templateUrl: "/html/homeView",
controller: "homeController",
title:"首页",
params:{userId:null}
})
第二种:
参数直接出现在url内部,会自动转换为http://localhost/user/0010001/detail
$stateProvider.state('page.home', {
url:"/user/:userId/detail",
templateUrl: "/html/userDetailView",
controller: "userDetailController",
title:"会员详情",
params:{userId:null}
})
第三种:
参数不出现在地址栏中隐藏传入
$stateProvider.state('page.home', {
url:"/user/detail",
templateUrl: "/html/userDetailView",
controller: "userDetailController",
title:"会员详情",
params:{userId:null}
})
以上三种传参方式都使用下面这种方式跳转
$state.go("page.home",{userId:"0010001"});
如果是 ui-sref 的话是这样写的ui-sref="page.home({userId:'0010001'})",如果是在ng-repeat循环内部的话可以这样写,
<a ng-repeat="item in userList" ui-sref="page.home({userId:item.userId})" ng-bind="item.name"></a>
获取的时候都一样
$stateParams.userId