I am creating an angular application using angular -ui-router. The backend has a REST api that gives me the url of the form based on the ticket id. In app.js, I want to dynamically install a template based on a request to this REST service. Example:
$stateProvider .state('form', { url: '/form/:id', templateProvider: function ($resource, formResolver, $stateParams) { //formResolver calls the REST API with the form id and gets back a URL. return formResolver.resolve($stateParams.id).then(function(url) { return $resource(url).get(); }; }, controller: 'MyCtrl' });
The problem is that I am returning a promise, and templateProvider requires a content string. What I would like to do is simply return the url:
$stateProvider .state('form', { url: '/form/:id',
But I don't get dependency injection when using templateUrl instead of templateProvider as per https://github.com/angular-ui/ui-router/wiki#wiki-templates and I still have a problem returning the promise. I think maybe my only solution is not to use the promise of api.
source share