当我运行build -prod时,我收到以下警告。
Warning: Can't resolve all parameters for UsersPermissionsService in C:/SourceControl/Test.Client/src/app/shared/users/users-permissions.service.ts: (?, ?, ?). This will become an error in Angular v5.x
Warning: Can't resolve all parameters for UsersPermissionsService in C:/SourceControl/Test.Client/src/app/shared/users/users-permissions.service.ts: (?, ?, ?). This will become an error in Angular v5.x
我的代码如下:
import { Injectable } from '@angular/core';
@Injectable()
export class UsersPermissionsService {
public USERS_CREATE_PERMISSION: string = '';
public USERS_UPDATE_PERMISSION: string = '';
public USERS_DELETE_PERMISSION: string = '';
constructor(public UsersCreatePermission: string,
public UsersUpdatePermission: string,
public UsersDeletePermission: string) {
this.USERS_CREATE_PERMISSION = UsersCreatePermission;
this.USERS_UPDATE_PERMISSION = UsersUpdatePermission;
this.USERS_DELETE_PERMISSION = UsersDeletePermission;
}
}
@Injectable()
export class UserModulePermissionsService extends UserPermissionsService {
constructor() {
super("ClientsCreate",
"ClientsEdit",
"ClientsDelete");
}
}
@Component({
templateUrl: './users-permissions.component.html',
providers: [UsersPermissionsService]
})
export class UsersPermissionsComponent {
constructor(public usersPermissionsService: UsersPermissionsService) {
}
}
在我的懒惰加载模块中我有:
providers: [
{ provide: UsersPermissionsService, useClass: UserModulePermissionsService }
]
现在,角度5已经出来,我需要更新,并且消息显示此警告将成为错误。
不明白这里的问题是什么。
答案 0 :(得分:27)
从基类中删除@Injectable
装饰器。你应该只在Angular应该直接实例化的类中包含那个装饰器(或任何装饰器)(并且这样做时也可以使用注入器解析它们的构造函数参数)。
因为很明显,在你的情况下,基类不是直接用angular实例化的(它具有注入器不知道的构造函数参数),你应该从中移除装饰器。
答案 1 :(得分:0)
得到这一点是因为我试图向服务的父项添加参数
A
constructor(logger: loggerService, someData: myData)
B extends A
constructor (logger: loggerService, new myData())
对我来说,解决方案是另一种设置someData的方法...
答案 2 :(得分:0)