Here I am going to explain how to add active class on dynamically added content or link while on clicking. I have explained same using Angular 2/4 concept as well check this link for that.
View
<ul>
<li ng-repeat="datalist in datalists" ng-click="select(datalist)"
ng-class="{active: isActive(datalist)}" >
<div>{{ datalist.name }}</div>
</li>
</ul>
Controller
$scope.select= function(item) {
$scope.selected = item;
};
$scope.isActive = function(item) {
return $scope.selected === item;
};
Click on any link, active class will be added to the active element.
But if we need to remove the active class on clicking the item again.Refer this post Add and remove active class on click Angular
Related Posts
1. Angular ng-repeate in directive
3. Angular js client side show more pagination
5. Simple client side sorting in angular
6. Add and remove active class on click Angular
7. Add a class for everything clicked - angular
8. Toggle click on dynamic menu items - Angular
Is there a way to bring the selected item in view? Like , for a long list, the user should not scroll down to see the selected item. It should be right on the screen in view. Any help would be appreciated
ReplyDeleteYou can add some index on selected item and also add sorting on the list. So the selected items will come in top. Hope it is clear.
DeleteThis helped me out . Thank you
ReplyDeletethis is great. Thank you
ReplyDeleteThank you!!
ReplyDeleteYou did make it easy, Thank you!
ReplyDeleteThank U So sooo Much
ReplyDeleteThank you!! :D
ReplyDeletewow :D
ReplyDeletethank you!!
ReplyDeleteyou saved my day <3
thanks, you save me my day...
ReplyDeleteregards.
Great post. I used to be checking constantly this blog and
ReplyDeleteI am impressed! Very helpful information specifically the closing phase :
) I take care of such info a lot. I used to be seeking this certain information for
a very long time. Thank you and good luck.
can I select the item through the code???
ReplyDelete