AngularJS: Returning a promise in a directive template function

As mentioned in the header, I would like to return the promise in the template function of the ie directive:

angular.module('someModule', []) //... .directive('someDirective', function() { return { //... restrict: 'E', template: function() { var deferred = $q.defer(); //Some Async function which will call deferred.resolve return deferred.promise; //Promise not supported by template property } }; }); 

Since the template property does not support this, is there any (simple) way to "emulate" this?

It seems like the solution is my best bet, but it's hard for me to find a suitable way to apply the template downloaded from WebSocket in the resolution method.

My goal is to use one WebSocket connection for all communications.

+2
source share
2 answers

You can try a different approach:

 app.run(function($templateCache, myTemplateLoader) { myTemplateLoader.load('templateName').then(function(content) { $templateCache.put('templateName', content); }); }); 

And now you can just use the templateUrl property in your directives:

 app.directive('someDirective', function() { return { // ... templateUrl: 'templateName' }; }); 
+1
source

In the solution, return the template and please follow the example of the dan wahlin dynamic boot controller and do the same as the routeResolver.resolve function for your directive

http://weblogs.asp.net/dwahlin/archive/2013/05/22/dynamically-loading-controllers-and-views-with-angularjs-and-requirejs.aspx

Please let me know if this does not work, I will create a plunker and update it.

0
source

All Articles