我希望仅在$state.current.nameequals 时显示一块HTML about.list。到目前为止,我有以下代码,但是根据状态,它似乎并未切换元素。
$state.current.name
about.list
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; })
data-ng-show="$state.includes('about.list')"