Angular2给类型错误参数“ElementRef”是不能分配给类型的参数“ViewContainerRef”
问题描述:
我使用角CLI创建angular2应用程序,但是当我使用下面的构造函数,它会给错误这样Angular2给类型错误参数“ElementRef”是不能分配给类型的参数“ViewContainerRef”
错误
Argument of type 'ElementRef' is not assignable to parameter of type 'ViewContainerRef'. Property 'element' is missing in type 'ElementRef'.
我的构造函数是
constructor(_elementRef: ElementRef, _loader: DynamicComponentLoader,_parentRouter: Router, @Attribute('name') nameAttr: string, private userService: LoginComponent)
{
super(_elementRef, _loader, _parentRouter, nameAttr);
this.parentRouter = _parentRouter;
this.publicRoutes = ['', 'login', 'signup'];
}
什么是错我的代码?我正在使用angular2 rc.3
答
将ViewContainerRef添加到导入以及构造函数中,然后在您使用elementRef的地方使用它。
显然这最近已经改变,现在你不能将elementRef传递给ViewContainerRef。
import {Component, DynamicComponentLoader, ElementRef, ViewContainerRef} from '@angular/core';
....
constructor(_elementRef: ElementRef, _viewContainerRef: ViewContainerRef, _loader: DynamicComponentLoader, ...)
{
super(_viewContainerRef, _loader, ...);
}
这个类是如何构造的? –
您构建或者让您支持Angular DI? –
我从博客获得了关于认证的信息。 –