Angular.js:当 $state.current.name 为特定值时的 ng-show 元素 [英] Angular.js: ng-show element when $state.current.name is a certain value
本文介绍了Angular.js:当 $state.current.name 为特定值时的 ng-show 元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望仅当 $state.current.name
等于 about.list
时才显示 HTML 块.到目前为止,我有以下代码,但它似乎没有根据状态切换元素.
I am looking to show a block of HTML only when $state.current.name
equals about.list
. So far I have the following code but it doesn't seem to be toggling the element depending on the state.
index.html
<nav class="global-navigation">
<ul class="list">
<li class="list-item">
<a class="list-item-link" ui-sref="home">
Home
</a>
</li>
<li class="list-item">
<a class="list-item-link" ui-sref="about">
About
</a>
</li>
<li class="list-item" ng-show="$state.current.name == 'about.list'">
<a class="list-item-link" ui-sref="about.list">
List
</a>
</li>
</ul>
</nav>
app.js
var myApp = angular.module('myApp', ['ui.router'])
.config(['$urlRouterProvider', '$stateProvider',
function($urlRouterProvider, $stateProvider) {
$urlRouterProvider.otherwise('/404.html');
$stateProvider.
// Home
state('home', {
url: '/',
templateUrl: 'partials/_home.html',
controller: 'homeCtrl'
}).
// About
state('about', {
url: '/about',
templateUrl: 'partials/_about.html',
controller: 'aboutCtrl'
}).
// About List
state('about.list', {
url: '/list',
controller: 'aboutCtrl',
templateUrl: 'partials/_about.list.html',
views: {
'list': { templateUrl: 'partials/_about.list.html' }
}
});
}]
);
推荐答案
或
.run(function ($state,$rootScope) {
$rootScope.$state = $state;
})
HTML
data-ng-show="$state.includes('about.list')"
这篇关于Angular.js:当 $state.current.name 为特定值时的 ng-show 元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文