Home >php教程 >PHP开发 >AngularJS implements a method of dynamically loading templates based on variable changes

AngularJS implements a method of dynamically loading templates based on variable changes

高洛峰
高洛峰Original
2016-12-07 15:48:071153browse

The example in this article describes how AngularJS implements dynamic loading of templates based on variable changes. Share it with everyone for your reference, as follows:

directive:

return {
    restrict: 'E',
    replace: true,
    templateUrl: 'app/view/order.html',
    link: function (scope, element, attrs) {
      scope.Type = attrs.Type;
    }
};

Template:

<div ng-switch on="item.Type">
 <div ng-switch-when="1"><ng-include src="&#39;views/1.html&#39;"></ng-include></div>
 <div ng-switch-when="2"><ng-include src="&#39;views/2.html&#39;"></ng-include></div>
 <div ng-switch-when="3"><ng-include src="&#39;views/3.html&#39;"></ng-include></div>
</div>

I hope this article will be helpful to everyone in AngularJS programming.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn