动态templateUrl – AngularJS
所以从角度1.1.4,你可以有一个动态的模板网址.从
here,
我如何利用这个来生成一个基于我的指令的属性的动态模板?显然这不起作用,因为tAttrs.templateType只是字符串“templateType” templateUrl: function (tElement,tAttrs) { if (tAttrs.templateType == 'search') { return '/b/js/vendor/angular-ui/template/typeahead/typeahead.html' } else { return '/b/js/vendor/angular-ui/template/typeahead/typeahead2.html' } } 鉴于我无法访问该范围,我该如何管理?
在AngularJS中也可以创建动态模板:
在您的指令中使用: template : '<div ng-include="getTemplateUrl()"></div>' 现在您的控制器可能会决定使用哪个模板: $scope.getTemplateUrl = function() { return '/template/angular/search'; }; 由于您可以访问范围参数,您还可以执行以下操作: $scope.getTemplateUrl = function() { return '/template/angular/search/' + $scope.query; }; 所以您的服务器可以为您创建一个动态模板. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |