【发布时间】:2017-12-06 10:33:26
【问题描述】:
我正在尝试在 angularjs 中使用我的 ng2 指令,但无法使其正常工作。我已经看到 downgradeComponent 使用 retric: 'E' 作为 angularjs 指令,这意味着它仅限于元素。有谁知道如何处理这个问题?
我尝试在 Angular js 中简单地使用我的指令,但它不起作用。 我正在使用 UpgradeModule 进行混合引导。
这是我的指令。
@Directive({
selector: '[test-directive]'
})
export class TestDirective implements OnInit {
@Input("test-directive") testDirective: string;
constructor(private el: ElementRef, private renderer: Renderer) {
}
ngOnInit() {
console.log("color is = " + this.testDirective);
this.renderer.setElementStyle(this.el.nativeElement, 'background-color', this.testDirective);
}
}
我尝试在 AngularJS 中将其用作属性(尝试将其用作 [test-directive] 和 test-directive。
我在这里遗漏了什么吗?因为我在网上搜索并没有找到很多关于这个问题的信息。
【问题讨论】:
-
这是我在 Angular 教程中的示例 plnkr.co/edit/jE4FTbnEWTuuYasXNvEX?p=preview angular.io/guide/…
-
你能在 plunker 中重现你的问题吗?
-
在你的例子中(yurzui)我没有看到属性的使用,我会尝试在你的例子中重现它。
-
plnkr.co/edit/dZaKSNlPjl6M6Jc4bubG?p=preview 这是一个例子,看看 test-attribute,它在 angular2 中有效,但在 angular.js (index.html) 中无效。我尝试降级指令,但无法完成。
标签: javascript angularjs angular