goh*_*goh 36 javascript angularjs angularjs-directive
我有以下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>
Run Code Online (Sandbox Code Playgroud)
以及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
}
});
Run Code Online (Sandbox Code Playgroud)
究竟是什么角度投掷我的意思是什么?
Error: Multiple directives [tbox, resizable] asking for template on: <div class="editbox" resizable="" editoptions="" ng-repeat="tb in textBoxes" ng-model="tb">
Run Code Online (Sandbox Code Playgroud)
jsfiddle at http://jsfiddle.net/sEZM3/
Woj*_*ski 24
如果您尝试错误地多次加载相同的指令代码,则可能会出现相同的错误.特别是当你将每个Angular项目(如指令)保存在单独的文件中并且每个单独的行包含单独的行时,可能会发生这种情况.那是我的情况.
可调整大小指令不正确。该ng-transclude指令必须应用于最里面的元素,因为它的内容将被丢弃并替换为嵌入的内容。
您应该使用(更正的)可调整大小的元素指令包围tbox指令模板。我不知道editoptions属性的作用,但如果它也是一个指令,那么它也不应该有模板。
我的意思是这样的:
appModule.directive('resizable', function($compile, $document) {
return {
restrict: "E",
template: '<div ng-style="{top:tb.x, left:tb.y, height:tb.height, width:tb.width}" ng-transclude></div>',
transclude: true,
replace: true,
//...
appModule.directive('tbox', function($document) {
return {
restrict: "E",
template: '<resizable><div class="editbox" editoptions>{{tb.text}}</div></resizable>',
replace: true,
//...
Run Code Online (Sandbox Code Playgroud)
结果:
<div ng-style="{top:tb.x, left:tb.y, height:tb.height, width:tb.width}" ng-transclude>
<div class="editbox" editoptions>{{tb.text}}</div>
</div>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
38220 次 |
| 最近记录: |