Usually, if you want to use what is updated asynchronously to be displayed in the view without having to write controller code (which is the case in your question, since you wanted to call the function inside ng-view), then you need to return an empty placeholder object and Either combine the result of the promise into it, or update the property of this object, which you can reference in the view.
Your question is too abstract to find out how to properly approach this to make sense for your application, but here is the general (and abstracted) plunker idea here :
.factory('promiseService', function($q){ return { someDeferredThing: function(){ var placeholder = {}; var d = $q.defer(); d.promise.then(function(text){ placeholder.text = text; }); d.resolve("hi"); return placeholder; } } )
The service returns an object that is updated with the promise, and not the promise itself. If you return a promise, you need to deal with .then() , etc., in order to get the value.
.controller('appCtrl', function($scope, promiseService){ $scope.deferredResult = promiseService.someDeferredThing(); });
This is how you assign a scope value.
$scope.deferredResult.text will be undefined until the promise is resolved, then it will be defined and resolved to "text" . Thus, your view should handle the undefined state for a short time - it is usually very simple to do this using ng-show .
source share