【问题标题】:Downgarde angular 2 directive or at least being able to use it in angular js降级 angular 2 指令或至少能够在 angular js 中使用它
【发布时间】: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。

我在这里遗漏了什么吗?因为我在网上搜索并没有找到很多关于这个问题的信息。

【问题讨论】:

标签: javascript angularjs angular


【解决方案1】:

正如我所见,在upgradeAdapter 中只给你downgradeNg2ProviderdowngradeNg2Component,事实上,downgradeNg2Component 总是使用“E”。 (https://github.com/angular/angular/blob/master/packages/upgrade/src/common/downgrade_component.ts#L70)

看看Downgrade NG2 Directive to AngularJS。我还没有测试过,但问题的作者说,不需要降级指令,你可以直接使用它。

【讨论】:

  • 是的,我看到了,并尝试在 angular.js 中使用我的 angular 2 指令,但没有成功。但是您是否碰巧知道 PRAISER 的意思是“只需将其作为声明添加到您的应用程序中即可”?哪个应用程序 angular 2 或 angular.js?
猜你喜欢
  • 1970-01-01
  • 2020-04-01
  • 2016-12-29
  • 2017-10-19
  • 2018-01-17
  • 2017-09-24
  • 2017-10-28
  • 2017-07-09
  • 2017-09-30
相关资源
最近更新 更多