admin管理员组文章数量:1391960
In my Angular JS application, I have 2 views - v1 and v2 and 1 controller - appCtrl.
I have configured UI router as below
.state('profile.v1', {
url: '/v1',
templateUrl: 'v1.html',
controller: 'appCtrl'
})
.state('profile.v2', {
url: '/v2',
templateUrl: 'v2.html',
controller: 'appCtrl'
})
I have 2 functions in appCtrl - fv1 and fv2.
I want to execute fv1 when route '/v1' is called, fv2 when route '/v2' is called.
Can somebody suggest?
In my Angular JS application, I have 2 views - v1 and v2 and 1 controller - appCtrl.
I have configured UI router as below
.state('profile.v1', {
url: '/v1',
templateUrl: 'v1.html',
controller: 'appCtrl'
})
.state('profile.v2', {
url: '/v2',
templateUrl: 'v2.html',
controller: 'appCtrl'
})
I have 2 functions in appCtrl - fv1 and fv2.
I want to execute fv1 when route '/v1' is called, fv2 when route '/v2' is called.
Can somebody suggest?
Share Improve this question asked Jul 16, 2016 at 18:12 Kalyan Chakravarthy SKalyan Chakravarthy S 7962 gold badges8 silver badges24 bronze badges2 Answers
Reset to default 5Inject $state
into the controller, and check $state.current.name
- It should be profile.v1
or profile.v2
, depending on what state you're currently in
Another way you can do this with one state declaration is:
.state('profile.detail', {
url: '/:version',
templateUrl: function($stateParams){
return $stateParams.version +'.html';
},
controller: 'appCtrl'
})
Then inject $stateParams in controller and check $stateParams.version
本文标签: javascriptUI router same controller for multiple statesStack Overflow
版权声明:本文标题:javascript - UI router same controller for multiple states - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744624050a2616207.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论