本文介绍了要求模板的多个指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下HTML:
<div style="border:1px solid; height:300px; width:500px; position:relative; left:100px" id="canvas">
<tbox ng-repeat="tb in textBoxes" ng-model="tb">
</tbox>
</div>
以下2条指令
appModule.directive('resizable', function($compile, $document) {
return {
restrict: "A",
template: '<div ng-style="{top:tb.x, left:tb.y, height:tb.height, width:tb.width}" ng-transclude><span class="scale">s</span></div>',
transclude: true,
replace: true,
require: 'ngModel'
}
});
appModule.directive('tbox', function($document) {
return {
restrict: "E",
template: '<div class="editbox" resizable editoptions>{{tb.text}}</div>',
replace: true
}
});
角度给我带来的以下错误究竟是什么意思?
What exactly does the following error that angular is throwing me means?
Error: Multiple directives [tbox, resizable] asking for template on: <div class="editbox" resizable="" editoptions="" ng-repeat="tb in textBoxes" ng-model="tb">
jsfiddle at
jsfiddle at http://jsfiddle.net/sEZM3/
推荐答案
你的两个指令都试图替换dom中的元素。尝试删除指令定义对象中的 replace:true
行。
Both of your directives are trying to replace the element in the dom. Try removing the the replace: true
lines in your directive definition object.
这篇关于要求模板的多个指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!