AngularJS ngClass conditional for multiple variable in sorting -


i using multiple-sorting in angularjs here want add class on clicked li tag, working fine when using single value sorting code below:

<li ng-class="{ active:sorttype === 'rollno'}"><a ng-click="sorttype = 'rollno';"><span>sort rollno</span></a></li>  <li ng-class="{ active: sorttype === 'marks'}"><a  ng-click="sorttype = 'marks';"><span>sort marks</span></a></li> 

but when use multiple-value sorting not changing class expected in code below:

  <li ng-class="{ active:sorttype === ['rollno','marks']}"><a ng-click="sorttype = ['rollno','marks'];"><span>sort rollno</span></a></li>  <li ng-class="{ active: sorttype === ['marks','rollno']}"><a  ng-click="sorttype = ['marks','rollno'];"><span>sort marks</span></a></li> 

my sorting working fine issue in changing class on sorted li tag. in controller:

$scope.sorttype=''; 

an array not equal array in javascript, if both contain same strings:

console.log(['a'] === ['a']); // prints false 

so need way know if sort type ['rollno','marks'] or ['marks','rollno'].

you use

ng-class="{ active: sorttype[0] === 'rollno' }" 

or add function controller like

$scope.issorttypeequalto = function(sorttype) {     return angular.equals($scope.sorttype, sorttype); }; 

and use

ng-class="{ active: issorttypeequalto(['rollno','marks']) }" 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -