This is probably the complete newb question ... an apology, but I can't put it into my head.
In many angular docs / examples, I see asynchronous functions wrapped in timeout blocks. Many of them are wrapped in setTimeout () and require explicit use.
if (!$scope.$$phase) {
$scope.$apply();
}
Given that angular provides $ timeout, the above code just seems to be outdated or incorrect, and inside of angular, $ timeout should always be preferred. However, I am distracted.
Here is an example code snippet taken from: http://markdalgleish.com/2013/06/using-promises-in-angularjs-views/
var myModule = angular.module('myModule', []);
myModule.factory('HelloWorld', function($timeout) {
var getMessages = function(callback) {
$timeout(function() {
callback(['Hello', 'world!']);
}, 2000);
};
return {
getMessages: getMessages
};
});
- , . - , ? :
var myModule = angular.module('myModule', []);
myModule.factory('HelloWorld', function() {
var getMessages = function(callback) {
callback(['Hello', 'world!']);
};
return {
getMessages: getMessages
};
});
?