【发布时间】:2016-12-14 02:11:10
【问题描述】:
我尝试使用指令参数化页面模板。 我有一个具有“类型”值的对象数组。当类型不同时,我想使用不同的模板。
这是我尝试过的:
directive.js
angular.module('core')
.directive('mySolutionDisplay', function () {
return {
restrict: 'E',
scope: {
solution: '='
},
templateUrl: function (elem, attr) {
return 'path/to/template/solution-'+attr.type+'.template.html';
}
};
});
view.html
<div class="row">
<my-solution-display type="vm.solution[0].type" solution="vm.solution"></my-solution-display>
</div>
我收到以下错误:
angular.js:11706 Error: [$compile:tpload] Failed to load template: path/to/template/solution-vm.solution[0].type.template.html
我尝试将type="vm.solution[0].type" 替换为type="{{vm.solution[0].type}}",但它只是在错误消息中添加了大括号。
【问题讨论】:
-
解决方案显示> -
你试过这样吗,我认为在 type="" 它不能解析变量名,你可以尝试在那里添加花括号
标签: javascript angularjs angularjs-directive