2017-07-03 39 views
6

我想在angularjs中使用我的ng2指令,但無法讓它工作。我已經看到downgradeComponent對angularjs指令使用限制:'E',這意味着它僅限於元素。任何人都知道如何處理這個問題?Downgarde角2指令或至少能夠在角js中使用它

我試過簡單地使用我的指令在角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作爲一個屬性(因爲我在網上搜索試圖使用它作爲[測試指令]和測試指令。

我在這裏失去了一些東西?並沒有發現關於這個問題的大量信息。

+0

這是我的角度教程示例https://plnkr.co/edit/jE4FTbnEWTuuYasXNvEX?p=preview https://angular.io/guide/upgrade#transcluding-angular-content-into-angularjs-component-directives – yurzui

+0

你能重現你的問題嗎? – yurzui

+0

在你的例子(yurzui)中,我沒有看到使用屬性,我會嘗試在你的例子中重現它。 –

回答

0

正如我所看到的,在upgradeAdapter只給你downgradeNg2ProviderdowngradeNg2Component而事實上,downgradeNg2Component總是使用「E」。(https://github.com/angular/angular/blob/master/packages/upgrade/src/common/downgrade_component.ts#L70

看看Downgrade NG2 Directive to AngularJS。我沒有測試過,但問題的作者說,沒有必要降級指令,你可以直接使用它。

+0

是的,我看到了這一點,並嘗試在angular.js中使用我的angular 2指令,它沒有奏效。但是你碰巧知道PRAISER的意思是「只需將它作爲聲明添加到你的應用程序中,它就可以工作」?哪個應用程序的角2或angular.js? –