I\'m having an issue with custom directives that\'s driving me crazy. I\'m trying to create the following custom (attribute) directive:
angular.module(\'comp
I have this problem too. I think it's a problem in Angular. There is a ticket on GitHub to "beef up $resource futures" which would probably address this issue, as what you really need is access to the promise object for the resource you have.
Or, the watchers could wait to fire until the promise is resolved.
In the meantime, a slightly more elegant way to fix this which doesn't require a timeout is to reassign the scope property that is being watched from the success callback on the $resource. This will cause the watcher to fire again at the appropriate time.
A timeout with no delay is just putting the evaluation of the deferred function on the end of the current stack - in your case, your resource happened to be resolved by then, but this could be a problem if the server is having a case of the Mondays.
Example:
$scope.myAttr = MyResource.fetch(
function (resource) { $scope.myAttr = new MyResource(angular.copy(resource)); }
);