In order to handle asynchronous data, it is essential to return a promise. This promise indicates that the data has not been retrieved yet, but will be resolved once the $timeout service completes its task.
The $q
service can be utilized for this purpose. Check out the documentation.
To achieve this functionality, you can use code like the following:
function($timeout) {
var deferred = $q.defer();
$timeout(function() {
data = createBreadcrumbs();
deferred.resolve(data);
}, 1000);
return deferred.promise;
}
As mentioned by @Bergi, the following code snippet demonstrates another approach:
$get: function($timeout) {
return $timeout(function() { return createBreadcrumbs();})
}