Home > php教程 > PHP开发 > body text

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

高洛峰
Release: 2016-12-07 15:48:07
Original
1122 people have browsed it

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;
    }
};
Copy after login

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>
Copy after login

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


Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template