本文實例講述了AngularJS實作根據變數改變動態載入模板的方法。分享給大家參考,如下:
directive:
return { restrict: 'E', replace: true, templateUrl: 'app/view/order.html', link: function (scope, element, attrs) { scope.Type = attrs.Type; } };
模板:
<div ng-switch on="item.Type"> <div ng-switch-when="1"><ng-include src="'views/1.html'"></ng-include></div> <div ng-switch-when="2"><ng-include src="'views/2.html'"></ng-include></div> <div ng-switch-when="3"><ng-include src="'views/3.html'"></ng-include></div> </div>