Dynamic templateUrl - AngularJS

后端 未结 4 463
南笙
南笙 2020-12-10 02:40

So as of Angular 1.1.4, you can have a dynamic template url. From here,

templateUrl - Same as template but the template is loaded from the specified URL

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-10 03:04

    The following is also possible for creating dynamic templates in AngularJS: In your directive use:

    template : '
    '

    Now your controller may decide which template to use:

    $scope.getTemplateUrl = function() {
      return '/template/angular/search';
    };
    

    Because you have access to your scope parameters, you could also do:

    $scope.getTemplateUrl = function() {
      return '/template/angular/search/' + $scope.query;
    };
    

    So your server could create a dynamic template for you.

提交回复
热议问题