【发布时间】:2015-08-12 16:38:09
【问题描述】:
我想在运行时使用 ng-attr-x1={{some scope varaible}} 添加 svg 元素行。 我尝试了两种方法: 我尝试使用 $compile 的一种方式:
var g=angular.element(document.createElementNS("http://www.w3.org/2000/svg", "g"));
var line=$compile('<line ng-attr-x1={{$scope.array[array.length-1].x1}} ng-attr-y1={{$scope.array[array.length-1].y1}} ng-attr-x1={{$scope.array[array.length-1].x2}} ng-attr-x1={{$scope.array[array.length-1].y2}} style="with mandatory styling for line">')($scope);
g.append(line);
parentg.append(g);
在此方法中,行不显示,g 以 0px 的高度和宽度显示。
我有两种方式:
var line=angular.element(document.createElementNS("http://www.w3.org/2000/svg", "line"));
line.attr('ng-attr-x1','scopeVariable');
line.attr('ng-attr-x2','scopeVariable');
line.attr('ng-attr-y1','scopeVariable');
line.attr('ng-attr-Y2','scopeVariable');
在这个 ng-attr 属性中没有解析为 x 和 y。在 DOM 中显示为
【问题讨论】: