我正在使用这样的代码:
我的模板代码是这样的:
问题:
仅当我的 ui-router 状态为“anon.about”时,如何“ngShow”“header.html”中的“div”?
最佳答案
如果您需要检查模板中的状态,您可以执行以下操作:
ng-show="current == $state.includes('<Your State Name>')"
并将当前值作为作用域变量传递,就像当前具有该指令的状态一样。这可以通过注入(inject) $stateParams 依赖项来完成。
更新的代码:
在 header.html 中
<div class="">
<div data-ng-show="$root.currentStateName=='anon.about'">Test!</div>
<div>{{$root.currentStateName}}</div>
</div>
在 app.js 中:
.state('anon.about', {
url: '/about',
templateUrl: 'about.html',
controller: function($rootScope,$state){
console.log($state.current.name);
$rootScope.currentStateName = $state.current.name;
}
})
关于javascript - Angular ,ui-路由器 : how to ngShow from Directive template?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24663973/