javascript - The color of selected item on AngularJS disappears -
i need color of selected item not disappear after click other part of page.
index.html
<div class="collapse navbar-collapse navbar-collapse-bottom-right navbar-collapse-default"> <ul class="nav navbar-nav navbar-right navbar-bottom-right"> <li class="menuitem" ng-repeat="item in menu"><a href="/#!/{{item.url}}">{{item.title}}</a> </li> </ul> </div>
app.js
$rootscope.menu = [ { title: 'product', url: 'product' }, { title: 'about', url: 'about' }, { title: 'contact', url: 'contact' }, { title: 'register', url: 'register' }, { title: 'login', url: 'login' } ];
i add code don't work
app.controller('maincontroller', function ($scope, $rootscope) { $scope.isactive = function(item) { return $scope.selected === item; }; $rootscope.menu = [ { title: 'product', url: 'product' }, { title: 'about', url: 'about' }, { title: 'contact', url: 'contact' }, { title: 'register', url: 'register' }, { title: 'login', url: 'login' } ]; });
problem unresolved
ok how have made item generated using ng-repeat "selected" aka active.
i set ng-class"active" doing below.
hope helps
<div class="panel-body" id="repeate"> <div class="list-group" ng-show="song.length > 0" ng-repeat="s in song | orderby: 'date' :true | limitto: 100"> <a href="#" class="list-group-item" ng-class="{active: isactive(s)}" ng-click="select(s)">{{s.songname}}</a> </div> </div>
js add
$scope.select = function(i) { $scope.selected = i; }; $scope.isactive = function(item) { return $scope.selected === item; };
Comments
Post a Comment