I am doing my first steps with directives on AngularJS and this directive is not working for me.
I have an ng-repeat list
<ul ng-after-list-filter> <li ng-repeat="item in items | filter:activeFilter.filterType = activeFilter.filterValue">...</li> </ul> that is being filtered with $scope.activeFilter.filterValue
I am trying to create the ng-after-list-filter directive so it will execute after the list has been filtered so I can make a dom manipulation on that new ul element.
This is my directive that is not working:
myModule.directive('ngAfterListFilter',function(){ return { restrict: 'A', link: function(scope,element,attrs) { scope.$watch(scope.activeFilter.filterValue, function(val) { console.log('do something here'); }); } } }); How do I make it work? I assume that scope.activeFilter.filterValue is not being updated, but - it is in the scope, and it does get updated and the list gets filtered. and I am trying to watch on this variable so why isn't it working?
Is there a better way to create this directive? I mean - I want to run a DOM changes when the list get updated (adjust sizes of things). so is there a way to listen to the
$('ul').html()? I tried that but it outputs me an error that I put raw text in javascript