警告:无法解析UsersPermissionsService的所有参数这将成为Angular v5.x中的错误

前端之家收集整理的这篇文章主要介绍了警告:无法解析UsersPermissionsService的所有参数这将成为Angular v5.x中的错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我运行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已经出来,我将需要更新,并且消息说这个警告将成为错误.

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

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

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

原文链接:https://www.f2er.com/angularjs/141041.html

猜你在找的Angularjs相关文章