javascriptangularjsroute-provider

Angularjs: Get $routeprovider template from function


I've been reading some important parts of the docs and I found this page: https://docs.angularjs.org/api/ngRoute/provider/$routeProvider

Somewhere in there, it says that the route>template property can be either (String|Function).
I guess it should be a function that returns html formed-string. What i want to know is if it is possible to use an http request to get the html from the server and also how to write such code.

I know this would make angular request the partial on each navigation, which should be counter productive - but i have my reasons.


Solution

  • I guess it should be a function that returns html formed-string.

    Right, like:

    templateUrl: function(param) {
       return 'views/' + param.details + '.html' ;
    }
    

    What i want to know is if it is possible to use an http request to get the html from the server

    No, you cannot do that.

    The config loads first and you cannot inject $http into config