angular route $state.go('hospital_doctors', { hospital_id: hospital_id })传值页面刷新怎么保存

前端之家收集整理的这篇文章主要介绍了angular route $state.go('hospital_doctors', { hospital_id: hospital_id })传值页面刷新怎么保存前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

使用angular route $state.go('hospital_doctors',{ hospital_id: hospital_id })传值页面刷新之后发现值不见了,即$stateParams.hospital_idnull

解决办法是

.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依然能获取到你所传递的值

api地址

猜你在找的Angularjs相关文章