0

I want to load templateurl from $http call.

$stateProvider
.state('home', {
        url: '/',
        templateUrl: will be served by $http call from server
    });

Please suggest how i will implement this.

1

5 Answers 5

3

I would suggest to use the templateProvider. That could consume any amount of IoC params (including current $stateParams). Combined with $templateRequest, we also can easily get template from server and keep it cached:

.state('myState', 
{
    ...
    // instead of templateUrl
    templateProvider: ['$templateRequest', '$stateParams', 
    function($templateRequest,$stateParams){
      var pathToTemplate = '....html';
      // get the proper path from any IoC injected here

      return $templateRequest(pathToTemplate);

    }],

Check these:

Sign up to request clarification or add additional context in comments.

Comments

1

Angular has done it it in most elegant way .If you want to call your backend controller to request a jsp page for templateurl just call $http url like this

.state('inbox', {
        url: '/inbox',
        templateUrl:'jspController/inboxRecord',
        controller : 'inboxController'
    }) 

that url respond with jsp page in my case inboxrecord.jsp that will be rendered.

Comments

0

as templateUrl can also be a function you could easily do:

$stateProvider.state('home', {
  templateUrl: function ($stateParams){
    $http....success({
      return <whatever> + '.html';
    })
  }
})

Comments

0

You will need a controller to populate your template from the results, and bind scope values from your template.

 $stateProvider
.state('home', {
    url: '/',
    templateUrl: 'index.html',
    resolve {
        results:  function($http){
        return $http({method: 'GET', url: '/serverspi'})
           .then (function (data) {
               return process(data);
           });
     },   
   }
});

Comments

0

I used templateProvider (https://github.com/angular-ui/ui-router/wiki) and retrieved a JSON object that contained my template doing something like this:

templateProvider: function($http) {
        return $http.get("http://example.com/returnJSONobject")
                .then(function(res) {
                    return res.htmlTemplate;
                });
},

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.