我试图在 angularjs 中使用我的 ng2 指令,但无法让它工作。我已经看到 downgradeComponent 使用 restric: '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。
我是不是漏掉了什么?因为我在网上搜索过,并没有找到很多关于这个问题的信息。
最佳答案
正如我所见,在 upgradeAdapter
中只给你 downgradeNg2Provider
和 downgradeNg2Component
事实上,downgradeNg2Component
总是使用“E”。 ( https://github.com/angular/angular/blob/master/packages/upgrade/src/common/downgrade_component.ts#L70 )
看看 Downgrade NG2 Directive to AngularJS .我没有测试过,但问题的作者说,没有必要降级指令,你可以开箱即用。
关于javascript - 降级 angular 2 指令或至少能够在 angular js 中使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44880784/