There is an interesting phenomenon happening with my directive. It watches the height of an element that is being updated by a controller using a factory method to retrieve data. Strangely, unless I include a $timeout in that factory function, my watch does not get updated. Can anyone offer insight into why this is happening?
Here is a snippet of my controller:
$scope.update = function () {
apiService.getLinks(function (response) {
$scope.links = response;
// Attempting $scope.$apply() here results in the message that it's already in progress
});
}
quickLinksServices.factory('quickLinksAPIService', function ($http, $timeout) {
quickLinksAPI.getQuickLinks = function (success) {
// The watch in the directive doesn't trigger without this $timeout
$timeout(function () { }, 100);
$http({
method: 'JSON',
url: '/devices/getquicklinkcounts'
}).success(function (response) {
quickLinksAPI.quicklinks = response;
quickLinksAPI.saveQuickLinks();
success(response);
});
}
The specific directive I'm working with can be found here