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

后端 未结 2 1758
说谎
说谎 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.

    0 讨论(0)
  • 2020-12-31 02:32

    templateUrl can be a function accepting object of route parameters:

    .when('/pages/:pageName', {
        templateUrl: function(params) {
            return 'views/pages/' + params.pageName + '.html';
        },
        controller: 'MainController'
    });
    
    0 讨论(0)
提交回复
热议问题