Any ideas why angular watch did not work when class is added with jquery timeout function. The idea is that when jquery is fored to change class: angular to catch that new class. Working example in fiddle. When you scroll down you will see catched changing of class Solved: Fiddle
<div ng-app='myApp'>
<div ng-controller="Ctrl" class="holder">
<div class="pusher"></div>
<table id="table">
<thead>
<tr>
<th class="ui sticky gar" ng-repeat="friend in friends" add-remove-class>{{friend.name}}</th>
</tr>
</thead>
<tbody></tbody>
</table>
<div class="pusher"></div>
<div class="pusher"></div>
<div class="ui sticky" id="gar" add-remove-class>Garrrrr</div>
</div>
<p class="footer" ng-class="wohooOrNoo">footer</p>
</div>
var myApp = angular.module('myApp', []);
myApp.controller("Ctrl", function ($scope, $timeout) {
$('#gar').sticky();
$('gar').sticky();
$scope.friends = [
{name:'John', age:25, gender:'boy'},
{name:'Jessie', age:30, gender:'girl'},
{name:'Johanna', age:28, gender:'girl'},
{name:'Joy', age:15, gender:'girl'},
{name:'Mary', age:28, gender:'girl'},
{name:'Peter', age:95, gender:'boy'},
{name:'Sebastian', age:50, gender:'boy'},
{name:'Erika', age:27, gender:'girl'},
{name:'Patrick', age:40, gender:'boy'},
{name:'Samantha', age:60, gender:'girl'}
]
});
myApp.directive('addRemoveClass', function () {
return {
link: function link(scope, element, attrs) {
// create an observer instance
var observer = new MutationObserver(function (mutations) {
scope.$apply(function () {
if (element.hasClass('fixed')) {
alert("wee");
}
});
});
// configuration of the observer:
var config = {
attributes: true
};
// pass in the target node, as well as the observer options
var node = element.get(0);
observer.observe(node, config);
}
};
});