【发布时间】:2017-01-27 14:09:42
【问题描述】:
我正在将我的应用程序从带有 angular-webpack 脚手架的 angular2 RC5 迁移到带有 angular cli beta 14 的 angular 2 2.0.0。
我正在与这些错误作斗争:
未捕获的错误:无法解析 PublicInfoDao 的所有参数:(?, ?).CompileMetadataResolver.getDependenciesMetadata @ metadata_resolver.js:508CompileMetadataResolver.getTypeMetadata @ metadata_resolver.js:405(匿名函数)@ metadata_resolver.js:552CompileMetadataResolver.getProvidersMetadata @ metadata_resolver.js:532CompileMetadataResolver.getNgModuleMetadata @ metadata_resolver.js:285RuntimeCompiler._compileComponents @ runtime_compiler.js:126RuntimeCompiler._compileModuleAndComponents @ runtime_compiler.js:64RuntimeCompiler.compileModuleAsync @ runtime_compiler.js:55PlatformRef_._bootstrapModuleWithZone @ application_ref.js:303PlatformRef_.bootstrapModule @ application_ref.js:285(匿名函数)@ main.ts:13__webpack_require__ @ bootstrap db3609d…:52(匿名 函数)@.*$:7__webpack_require__@bootstrap db3609d…:52webpackJsonpCallback @ bootstrap db3609d…:23(匿名 函数)@main.bundle.js:1
和
metadata_resolver.js:278Uncaught 错误:意外值 由模块“AppModule”(匿名函数)声明的“AppComponent” @metadata_resolver.js:278CompileMetadataResolver.getNgModuleMetadata @metadata_resolver.js:265RuntimeCompiler._compileComponents @ runtime_compiler.js:126RuntimeCompiler._compileModuleAndComponents @ runtime_compiler.js:64RuntimeCompiler.compileModuleAsync @ runtime_compiler.js:55PlatformRef_._bootstrapModuleWithZone @ application_ref.js:303PlatformRef_.bootstrapModule @ application_ref.js:285(匿名函数)@ main.ts:13__webpack_require__ @ bootstrap db3609d…:52(匿名 函数)@.*$:7__webpack_require__@bootstrap db3609d…:52webpackJsonpCallback @ bootstrap db3609d…:23(匿名 函数)@main.bundle.js:1 1: https://github.com/preboot/angular2-webpack
如果我删除应用程序工作的几个组件,这是一个奇怪的行为。但是如果我添加一个简单的组件,例如:
@Component({
selector: 'tl-result-item',
templateUrl: "./resultitem.component.html",
styleUrls: ["./resultitem.component.scss"]
})
export class ResultItemComponent {
@Input()
result:Result;
constructor(){}
}
抛出第二个错误。如果我评论 @Input() 该应用程序有效。
如果我取消注释应用程序会引发相同的错误,并且如果我注释某些行,则错误会消失。
这些错误让我快疯了。我认为这应该是一个外部问题。
有什么想法吗?
更新:
第一个错误可能与https://github.com/AngularClass/angular2-webpack-starter#frequently-asked-questions有关(第二个问题) 我有几个问题要迁移到 angular 2.0.0 final。
更新2:
@NgModule({
providers: [
MetaService,
Title,
HttpInterceptor,
{provide: ConnectionBackend, useClass: XHRBackend},
{provide: Http, useExisting: HttpInterceptor},
{provide: Configuration, useClass: ConfigurationDevelopment}
],
imports: [
BrowserModule,
HttpModule,
FormsModule,
ReactiveFormsModule,
// APP_ROUTER_PROVIDERS
],
declarations: [
AppComponent,
ResultItemComponent,
TimestampToMomentPipe,
TimestampToTimePipe
],
bootstrap: [AppComponent]
})
export class AppModule {
}
更新3: 另一个在 Angular cli 中失败的代码示例。
这段代码可以正常工作:
this.publicService.all().subcribe(response => {
console.log(response);
});
此代码失败:
this.publicService.all().subcribe(response => {
deserialize(response)
});
上面解释的异常:
未捕获的错误:无法解析 PublicInfoDao 的所有参数:(?, ?)。
¿¿??
【问题讨论】:
-
你有重现这个问题的github repo吗?
-
否,但我可以验证问题与 angular-cli 有关。我正在使用旧的脚手架和 angular 2.0.0 工作正常。那么 angular-cli 会发生什么?
-
你能分享你的 app.module 文件吗?
-
你来了,你在想什么?我想知道你有什么想法。
-
我以为你在 app.module 中导入了错误的东西。但是一切都很清楚。也许你可以错误地导入提供程序。你可以创建调用环境文件来导入提供程序。github.com/AngularClass/angular2-webpack-starter/blob/master/…
标签: angular