Angular 从 8 升级到 9,无法解析任何注射剂的所有参数
Angular upgrade from 8 to 9, Can't resolve all parameters for any injectable
我最近将 Angular 8 升级到 Angular 9,似乎没有任何东西可以依赖注入。
我在我的项目中注释掉了很多代码,基本如下所示:
// configuration.state.ts
@State<ConfigurationStateModel>({
name: 'ConfigurationStateModel',
defaults: defaultConfiguration,
})
export class ConfigurationState {
constructor(
//private configurationService: ConfigurationService,
private configurationService: HeroService,
) { }
// .. irrelevant code
}
//hero.service.ts
// generated by ng g s heroservice
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class HeroService {
constructor() { }
}
错误
Error: Can't resolve all parameters for ConfigurationState: (?).
at getUndecoratedInjectableFactory (core.js:17311)
at injectableDefOrInjectorDefFactory (core.js:17295)
at providerToFactory (core.js:17363)
at providerToRecord (core.js:17345)
at R3Injector.processProvider (core.js:17161)
at core.js:17122
at core.js:1400
at Array.forEach ()
at deepForEach (core.js:1400)
at R3Injector.processInjectorType (core.js:17118)
显然对于 NGXS,所有状态现在都必须用 @Injectable()
修饰。
这不有效:
@Injectable()
@State<ConfigurationStateModel>({
name: 'ConfigurationStateModel',
defaults: defaultConfiguration,
})
export class ConfigurationState {
但在 @State
之后添加它:
@State<ConfigurationStateModel>({
name: 'ConfigurationStateModel',
defaults: defaultConfiguration,
})
@Injectable()
export class ConfigurationState {
我最近将 Angular 8 升级到 Angular 9,似乎没有任何东西可以依赖注入。
我在我的项目中注释掉了很多代码,基本如下所示:
// configuration.state.ts
@State<ConfigurationStateModel>({
name: 'ConfigurationStateModel',
defaults: defaultConfiguration,
})
export class ConfigurationState {
constructor(
//private configurationService: ConfigurationService,
private configurationService: HeroService,
) { }
// .. irrelevant code
}
//hero.service.ts
// generated by ng g s heroservice
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class HeroService {
constructor() { }
}
错误
Error: Can't resolve all parameters for ConfigurationState: (?).
at getUndecoratedInjectableFactory (core.js:17311)
at injectableDefOrInjectorDefFactory (core.js:17295)
at providerToFactory (core.js:17363)
at providerToRecord (core.js:17345)
at R3Injector.processProvider (core.js:17161)
at core.js:17122
at core.js:1400
at Array.forEach ()
at deepForEach (core.js:1400)
at R3Injector.processInjectorType (core.js:17118)
显然对于 NGXS,所有状态现在都必须用 @Injectable()
修饰。
这不有效:
@Injectable()
@State<ConfigurationStateModel>({
name: 'ConfigurationStateModel',
defaults: defaultConfiguration,
})
export class ConfigurationState {
但在 @State
之后添加它:
@State<ConfigurationStateModel>({
name: 'ConfigurationStateModel',
defaults: defaultConfiguration,
})
@Injectable()
export class ConfigurationState {