gpt4 book ai didi

angular - 警告 : Can't resolve all parameters for UsersPermissionsService This will become an error in Angular v5. x

转载 作者:太空狗 更新时间:2023-10-29 16:57:57 25 4
gpt4 key购买 nike

当我运行 ng 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 }
]

现在 angular 5 已经出来了,我需要更新,正如消息所说,这个警告将变成一个错误。

不明白这里真正的问题是什么。

最佳答案

从基类中删除 @Injectable 装饰器。你应该只在 Angular 应该直接实例化的类中包含那个装饰器(或任何与此相关的装饰器)(并且在这样做的同时也使用注入(inject)器解析它们的构造函数参数)。

因为很明显,在您的情况下,基类不会直接由 angular 实例化(它具有注入(inject)器不知道的构造函数参数),您应该从中删除装饰器。

关于angular - 警告 : Can't resolve all parameters for UsersPermissionsService This will become an error in Angular v5. x,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47222685/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com