使用angular route $state.go('hospital_doctors',{ hospital_id: hospital_id })
传值页面刷新之后发现值不见了,即$stateParams.hospital_id
是null
解决办法是
.state('hospital_doctors',{
url: '/hospital_doctors/:hospital_id',headText: '医院所有医生',templateUrl: '/assets/app/templates/hospital_doctors.html.erb',controller: 'hospital_doctorsController'
params: {
hospital_id: null
}
})
页面跳转还是按以前的来
$state.go('hospital_doctors',{ hospital_id: hospital_id })
接下来不管你怎么刷新值都在,因为它存在url里面了,如下
http://localhost:4000/#/manager/hospital_doctors/100
使用$stateParams.hospital_id获取即可
.state('doctorInfo',{
url: '/doctorInfo/:doctor_id',templateUrl: '/assets/adminAngular/app/templates/doctorInfo/index.html',controller: 'doctorInfoCtrl',params:{doctor_id: null}
})
.state('doctorInfo.personInfo',{
url: '/personInfo/:doctor_id',templateUrl: '/assets/adminAngular/app/templates/personInfo/index.html',controller: 'personInfoCtrl',params:{doctor_id: null}
})
.state('doctorInfo.statistics',{
url: '/statistics/:doctor_id',templateUrl: '/assets/adminAngular/app/templates/statistics/index.html',controller: 'statisticsCtrl',params:{doctor_id: null}
})
上面的路由如果你直接使用
$state.go('doctorInfo.personInfo',{doctor_id: id})
那你在doctorInfoCtrl,personInfoCtrl
里面使用
$stateParams.doctor_id
http://localhost:4000/#/doctorInfo/1/personInfo/1
看到上面的路由你应该已经不难看出通信原理了吧,即使浏览器刷新了,stateParams依然能获取到你所传递的值