javascript - 降级 angular 2 指令或至少能够在 angular js 中使用它

标签 javascript angularjs angular

我试图在 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 中只给你 downgradeNg2ProviderdowngradeNg2Component 事实上,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/

相关文章:

javascript - django-nvd3 Chart.tooltipContent 不是函数

c# - Javascript - 调用 ASP.NET WebService - 服务器方法 'methodName' 失败

javascript - 使用 javascript 对 HTML 表的项目进行分类

javascript - Angularjs $http.post - 将参数作为 JSON 发送到 ASPX webmethod

javascript - ng-click 以撤消事件 AngularJs

angular - 警告 : 1 rules skipped due to selector errors: legend + * -> Cannot read property 'type' of undefined

javascript - 将 jQuery 函数分配给变量不起作用,但包装它可以

angularjs - 蓝点表示 react 谷歌地图中的当前位置

angular - NgFor 不使用 Angular2 中的管道更新数据

angular - div中动态加载图片