AngularJS - use routeProvider “when” variables to construct templateUrl name?

后端 未结 2 1781
说谎
说谎 2020-12-31 01:51

So this is what I am trying to accomplish:

\'use strict\';

var app = angular.module(\'myModule\', [\'ngRoute\']);

app.config(function($routeProvider) {
  $         


        
2条回答
  •  长情又很酷
    2020-12-31 02:20

    templateUrl can be use as function with returning generated URL. We can manipulate url with passing argument which takes routeParams.

    See the example.

    .when('/:screenName/list',{
        templateUrl: function(params){
             return params.screenName +'/listUI'
        }
    })
    

    Hope this help.

提交回复
热议问题