Angular ui-routerProvider template never called

I need to pass the route parameter to the server responding with the template, so I'm trying to use templateProviderfor several articles / other documents.

I am not getting javascript errors, but the following templateProvidermethod is not even executed. When a property is templateUrlnot commented out, this route works fine.

$stateProvider
.state('org.contacts.add', {
  url: '/add',
  views: {
    'org@': {
      // templateUrl: '/templates/issues/add',
      controller: 'ContactsAddController',
      templateProvider: function($route, $templateCache, $http) {
          var url = '/templates/' + $route.current.params.org + '/contacts/add';
          $http.get(url, {cache: $templateCache}).then(function(html){
              return html;
          });
      }]
    }
  }
})

After some experimentation, it seems to $routecause problems. Taking this and using $stateParamsat least runs this code / controller.

However, as long as I see the ajax shooting and the correct html response, it never loads into the view.

    templateProvider: function ($stateParams, $http, $templateCache) {
        var url = '/templates/contacts/add';
        $http.get(url, {cache: $templateCache}).then(function(html){
            return html;
        });
    }
+4
source share
1 answer

, $promise . , - UI-:

$stateProvider.state('contacts', {
  templateProvider: function ($timeout, $stateParams) {
    return $timeout(function () {
      return '<h1>' + $stateParams.contactId + '</h1>'
    }, 100);
  }
})

, return $timeout(.... $promise, $http.get()?

+4

All Articles