I have a directive that watches the height of an element. That element is updated by a controller that uses a factory method to get data. Unless I have a $timeout
in that factory my watch never gets updated. Curious! Can anyone shed light onto why?
My controller:
$scope.update = function () {
apiService.getLinks(function (response) {
$scope.links = response;
// If I try $scope.$apply() here it says its already in progress, as you'd expect
});
}
quickLinksServices.factory('quickLinksAPIService', function ($http, $timeout) {
quickLinksAPI.getQuickLinks = function (success) {
//without this the watch in the directive doesnt get triggered
$timeout(function () { }, 100);
$http({
method: 'JSON',
url: '/devices/getquicklinkcounts'
}).success(function (response) {
quickLinksAPI.quicklinks = response;
quickLinksAPI.saveQuickLinks();
success(response);
});
}
The directive I'm using is here