我正在使用Angular的UI-Router,如下所示在我的网络应用中进行网址路由,如下所示:
$stateProvider.state('myState1', {
url: '/state1',
templateUrl: 'state1.html',
controller: 'MyState1Ctrl'
});
$stateProvider.state('myState2', {
url: '/state2',
templateUrl: 'state2.html',
controller: 'MyState2Ctrl'
});
在两个模板文件state1.html
,state2.html
的每一个中,我都有导航栏指令:<myapp-navigation-bar></myapp-navigation-bar>
但我希望导航栏的行为与myState1
或myState2
中的天气不同。如何从导航栏(或其模板)的控制器中检测到它处于哪种状态?
答案 0 :(得分:0)
根据 documentation ,您可以执行此操作,
.controller('MyState1Ctrl', function($scope, $state) {
$scope.statecurrent = $state.current;
});
答案 1 :(得分:0)
你也可以这样检查 -
.controller('MyState1Ctrl', function($scope, $state) {
if ($state.is("myState1")) {
//Add Logic
}
});