[英]Angular directive within d3 SVG
Is it possible to include an Angular directive within a d3 SVG
? 是否可以在d3 SVG
包含Angular指令?
node.append("foreignObject")
.attr("width", 100)
.attr("height", 100)
.append("xhtml:my-directive")
<my-directive></my-directive>
is created in the SVG
, but the controller never runs and the directive's HTML content is missing. <my-directive></my-directive>
是在SVG
创建的,但是控制器从不运行,并且指令的HTML内容丢失。 In a sibling of the SVG
, the directive renders correctly. 在SVG
的同级中,伪指令可正确呈现。
As of AngularJS 1.3.0-rc.5
, you can specify your directive as an SVG
by specifying templateNamespace: 'svg'
alongside replace: true
. 从AngularJS 1.3.0-rc.5
,您可以通过指定templateNamespace: 'svg'
以及replace: true
来将指令指定为SVG
。 Prior to this version, there was no real first-class support for SVG
and you'll find yourself hacking around if unable to move up from 1.2.x
. 在此版本之前,尚无真正的SVG
一流支持,如果无法从1.2.x
升级,您会发现自己正在四处寻找。 You'll also need to inject and leverage the $compile service to append a dynamic directive. 您还需要注入并利用$ compile服务来附加动态指令。 Observe the following simplified example... 观察下面的简化示例...
<svg id="mysvg">
<rect height="100" width="100" fill="dodgerblue"></rect>
</svg>
.controller('ctrl', function($scope, $compile) {
var node = angular.element(document.getElementById('mysvg'));
node.append($compile('<my-directive></my-directive>')($scope))
})
.directive('myDirective', function() {
return {
templateNamespace: 'svg',
template: '<rect height="10" width="100" fill="tomato"></rect>',
replace: true,
link: function(scope, elem, attrs) {
console.log('linked');
}
}
});
JSFiddle Link - working demo v.1.3.0 JSFiddle Link-工作演示v.1.3.0
You can also check out some project discussion here for the milestones of SVG
support within the AngularJS project. 您还可以在这里查看一些项目讨论,以了解AngularJS项目中SVG
支持的里程碑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.