如何解决从8角度升级到9,无法解析任何可注射的所有参数
我最近从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() { }
}
错误
错误:无法解析ConfigurationState的所有参数:(?)。
在getUndecoratedInjectableFactory(core.js:17311)
在injectableDefOrInjectorDefFactory(core.js:17295)
在providerToFactory(core.js:17363)
在providerToRecord(core.js:17345)
在R3Injector.processProvider(core.js:17161)
在core.js:17122
在core.js:1400
在Array.forEach()
在deepForEach(core.js:1400)
在R3Injector.processInjectorType(core.js:17118)
解决方法
显然,对于NGXS,现在必须用@Injectable()
装饰所有州。
这不有效:
@Injectable()
@State<ConfigurationStateModel>({
name: 'ConfigurationStateModel',defaults: defaultConfiguration,})
export class ConfigurationState {
但在@State
之后添加它:
@State<ConfigurationStateModel>({
name: 'ConfigurationStateModel',})
@Injectable()
export class ConfigurationState {
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。