【发布时间】:2013-11-23 11:41:12
【问题描述】:
我想在另一个指令中使用指令。
父指令在其模板中使用子指令。
这是我的代码。
HTML
<div ng-app="myApp">
<div ng-controller="Ctrl">
<svg>
<my-line></my-line>
</svg>
</div>
</div>
javascript
var myApp = angular.module('myApp',[
'myController',
'myDirectives'
]);
//Controller
var myControllers = angular.module('myControllers', []);
myControllers.controller('Ctrl', function($scope){
$scope.line = [
{ nodeId:'1'},
{ nodeId:'2'},
{ nodeId:'3'}
]
});
//Directives
var myDirectives = angular.module('myDirectives',[]);
myDirectives.directive('myLine',function(){
return {
restrict: 'E',
template:
'<g ng-repeat="node in line">' +
'<my-node node="{{node}}"></my-node>' +
'</g>'
};
});
myDirectives.directive('myNode',function(){
return {
restrict:'E',
scope:{
node:'=node'
},
template:
'<text x="0" y="0">{{node.nodeId}</text>'
}
});
这里是 jsfiddle 链接。
但是子指令没有显示。
我该怎么办?
【问题讨论】:
-
看看JSFiddle
-
感谢您的回复。这是使用父指令的一个很好的例子。但我想在父模板中使用子指令。
-
DOM节点和SVG节点是有区别的。 Angular 正在创建 DOM 节点。检查此线程:groups.google.com/forum/#!msg/angular/nP5JSuRuBMw/Wkv4DGMrtEUJ
标签: templates angularjs svg directive snap.svg