1

This question is similar to this: Angular ui-router templateProvider never called except in my case I am returning a promise and it still isn't working. The xhr request is never fired.

app.config(function($stateProvider, $urlRouterProvider){

      // For any unmatched url, send to /content
      $urlRouterProvider.otherwise("/content")

      $stateProvider.state('map1', {
           url: "/content/sectionI",
           templateProvider: function($http, $stateParams) {
            return $http({
              method: 'GET',
              url: '/contentMore',
              params: {request:"Section_I_Unlocked",part:"map"}
                }).then(function successCallback (html){
                    return html.data;
                });
            }
        });

    });

What am I doing wrong? I see the url change when I click on state map1 but the templateProvider never fires?

Community
  • 1
  • 1
Summer Developer
  • 2,056
  • 7
  • 31
  • 68
  • Does the state work if you use `template`? I'm not sure it has anything to do with `templateProvider`. [MCVE](http://stackoverflow.com/help/mcve) would help. – Estus Flask Jun 08 '16 at 15:15

1 Answers1

1

There is a working plunker

I adjusted a bit the url path (but mostly for plunker purposes, not sure how your server is configured), and the concept as is is working:

  $stateProvider.state('map1', {
    url: "/content/sectionI",
    templateProvider: function($http, $stateParams) {
      return $http({
        method: 'GET',
        url: 'contentMore.html',
        params: {
          request: "Section_I_Unlocked",
          part: "map"
        }
      }).then(function successCallback(html) {
        return html.data;
      });
    }
  });

Check it in action here

There are even more easy ways how to load data.. e.g. with combination templateProvider and $templateRequest:

Using templateRequest in angular + typescript ($templateRequest not a function)

Angular ui.router reload parent templateProvider

Community
  • 1
  • 1
Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
  • 1
    Well it's the `url` parameter, my server is using Laravel as a backend so the url is `contentMore` not `contentMore.html` so I will have to figure out how to fix that. – Summer Developer Jun 08 '16 at 17:51