我有看法:AngularJs活動導航項目的問題
<ul class="nav nav-pills" ng-controller="MenuItemCtrl as vm">
<li ng-repeat="item in names" class="col-lg-2 col-md-2 col-sm-12 col-xs-12" ng-click="select($index)" ng-class="{active: $index == selected}">
<a ng-show="{{item.up===true}}" href="#{{item.link}}">{{item.name}}</a>
</li>
</ul>
和控制器這樣的:
$scope.names = [{
name: "Main",
slug: "main",
active: true,
up:true,
inFooter:false,
link: "/"
}, {
name: "Pets",
slug: "pets",
active: false,
up:true,
link: "/pets"
}, {
name: "LDAdoption",
slug: "ldAdoption",
active: false,
inFooter:false,
up:true,
link: "/ldAdoption"
},{
name: "Impressum",
slug: "impressum",
active: false,
up:false,
inFooter:true,
link: "/impressum"
}, {
name: "Be a volunteer",
slug: "volunteer",
active: false,
inFooter:true,
up:false,
link: "/volunteer"
}, {
name: "Contact",
slug: "contact",
active: false,
up:true,
inFooter:true,
link: "/contact"
}];
$scope.selected = 0;
$scope.select= function(item) {
$scope.selected = item;
};
$scope.isActive = function(item) {
return $scope.selected === item;
};
我不明白爲什麼活動狀態不保持,如果我刷新我的網頁。我與ng-route一起工作,一切都很好,只是活動狀態工作錯了。你能幫我嗎?謝謝!
由於負荷後,你有'$ scope.selected = 0'和'$ scope.isActive()'將被解析成'0 === item'。 –
,我該怎麼辦? –
這取決於你想做什麼。 –