gpt4 book ai didi

javascript - Angular.js : ng-show element when $state. current.name 是某个值

转载 作者:行者123 更新时间:2023-12-03 06:54:42 24 4
gpt4 key购买 nike

我希望仅当 $state.current.name 等于 about.list 时才显示 HTML block 。到目前为止,我有以下代码,但它似乎没有根据状态切换元素。

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' }
}
});

}]

);

最佳答案

您可以使用诸如isStateincludedByState之类的过滤器。

ng-if="'about.list' | isState" // exactly 'about.list'

ng-if="'about' | includedByState" // works for about and its children about.*

关于javascript - Angular.js : ng-show element when $state. current.name 是某个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22748456/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com