angular - Angular 6:无法解析组件的所有参数:(?)
问题描述
我们已经使用 Angular v6.0.0-beta.3 很长时间了,但最近我们尝试升级到 6.1.3 版本。
我一直无法使用角度示意图进行升级,因为它们似乎不支持外部注册表(我们使用 Artifactory),所以我不得不手动升级它,所以很可能我搞砸了。
目前升级后我得到这个堆栈跟踪:
Uncaught Error: Can't resolve all parameters for LoginComponent: (?).
at syntaxError (compiler.js:1016)
at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver._getDependenciesMetadata (compiler.js:10917)
at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver._getTypeMetadata (compiler.js:10810)
at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver.getNonNormalizedDirectiveMetadata (compiler.js:10429)
at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver._getEntryComponentMetadata (compiler.js:11013)
at compiler.js:11004
at Array.forEach (<anonymous>)
at CompileMetadataResolver.push../node_modules/@angular/compiler/fesm5/compiler.js.CompileMetadataResolver._getEntryComponentsFromProvider (compiler.js:11003)
at compiler.js:10976
at Array.forEach (<anonymous>)
LoginComponent 注入 AuthService。如果我将 AuthService 放在 LoginComponent 的provide
数组属性中,那么它就会停止抱怨该错误,并为另一个组件提供相同的错误。我已经尝试用新providedIn: 'root'
配置替换所有 Injectable,但它仍然不起作用。我试过清理 npm 缓存并删除 node_modules 仍然是同样的问题。我对自己做错了什么感到迷茫。
在 AOT 中运行实际上可以正确启动应用程序,但是在使用某些组件(我认为是材料)时,我会得到这些堆栈跟踪:
ERROR TypeError: a[getSymbolIterator(...)] is not a function
at areIterablesEqual (core.js:5492)
at devModeEqual (core.js:5421)
at checkBindingNoChanges (core.js:7689)
at checkNoChangesNodeInline (core.js:10552)
at checkNoChangesNode (core.js:10541)
at debugCheckNoChangesNode (core.js:11144)
at debugCheckDirectivesFn (core.js:11072)
at Object.updateDirectives (login.component.html:37)
at Object.debugUpdateDirectives [as updateDirectives] (core.js:11061)
at checkNoChangesView (core.js:10440)
任何帮助将不胜感激。
编辑:LoginComponent 构造函数
constructor(
private authService: AuthService) {
}
AuthService 类声明
@Injectable()
export class AuthService {
我所有的提供程序都在 AppModule 中提供。
解决方案
@Inject
在 LoginComponent 中围绕 AuthService 实例化添加装饰器
constructor(
@Inject(AuthService) private authService: AuthService) {
}
这有助于编译器知道稍后将注入 AuthService。
推荐阅读
- ios - 如何以编程方式关闭上下文菜单(UIContextMenu)?
- spring-boot - 如何使用 RestAssured 在 Spring Boot 集成测试中为客户端调用设置端口?
- python - 动态任务生成中的意外气流行为
- javascript - Ag-grid:使用“agSelectCellEditor”时清除单元格
- c# - 命令行 api 与哪些版本的 .NET 兼容?
- c++ - 使用受保护成员通过继承类进行测试
- lua - Lua 跨越 C 调用边界
- c++ - 如何为具有 N 个节点的图生成每个可能的邻接矩阵?
- python - 文件同名时缺少 Python 代码覆盖率
- ios - XCode Build Phase script exit code 1 error React Native