【发布时间】:2017-05-31 04:45:24
【问题描述】:
我正在使用 Angularjs 组件和 ES6 来构建一个也使用 d3js 的应用程序。我正在使用属性指令进行 DOM 操作。由于组件具有范围,我试图在链接函数中访问它并在内部使用 $watch。我的怀疑来自我试图观察和访问的变量在 $scope.$ctrl 内。在这种情况下访问它们的正确方法是什么?
模板
<div class="card">
<svg network-svg>
</svg>
</div>
组件
export const NetworkComponent = {
template,
controller: class NetworkComponent {
constructor(CommService) {
'ngInject'
this.comm = CommService;
this.physicalTree = new NodeTree('physical');
this.virtualTree = new NodeTree('virtual');
this.pVisible = true;
}
}
}
指令 当前指令的代码,但返回未定义。
export const NetworkSvg = () => {
return {
restrict: 'A',
link($scope, $element, $attrs) {
$scope.$watch('virtualTree', function() {
});
$scope.$watch('physicalTree', function() {
});
}
}
【问题讨论】:
标签: javascript angularjs ecmascript-6