0
我想降级角2指令与Angular 1.5应用程序一起使用。 我们能够降级Angular 2组件,但不能降级指令。角度2降级指令不工作
import { Directive, ElementRef, Input, Renderer } from '@angular/core';
import { UpgradeComponent } from '@angular/upgrade/static';
@Directive({
selector: 'myDir'
})
export class MyDirective {
constructor(public el: ElementRef, public renderer: Renderer) {
console.log('constructor');
}
ngOnInit() {
console.log("onInit");
}
}
angular.module(myapp)
.directive('myDir', downgradeComponent({ component: MyDirective }));
当我尝试在Angular 1应用程序中使用指令时,它不会触发构造函数或ngOnInit。
这就是我如何使用它。
<myDir></myDir>
谢谢!你的方法是否也适用于属性指令?说如果我们需要
– user636525不幸的是,角降级只支持组件作为元素而不是属性 – pezetem