我在許多之前的SO問題中都看到過這個錯誤,但是在升級到最新版本4.0.2之後,它們都沒有與這種情況相關。這不是一個循環的直接投資,並且似乎與polifills沒有關係。錯誤:無法解析XXX的所有參數:(?)。 Angular 4.0.2
我正在使用SystemJS
和jspm
(不是webpack),也許jspm
是與問題有關,但我不知道如何。
的應用程序入口點是main.ts:
import 'core-js/es7/reflect';
import 'zone.js/dist/zone';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule2 } from './app/app.module2';
platformBrowserDynamic().bootstrapModule(AppModule2);
我的模塊,app.module2.ts
,很簡單:
import { NgModule, Component } from '@angular/core';
import { HttpModule, Http } from '@angular/http';
import { BrowserModule } from '@angular/platform-browser';
@Component({
selector: 'app-home',
template: `<h2>Hola</h2>`
})
export class HomeComponent {
constructor(private http : Http) {
}
}
@NgModule({
imports: [
BrowserModule, HttpModule
],
declarations: [
HomeComponent
],
bootstrap: [ HomeComponent ],
entryComponents: [ ],
providers: [
]
})
export class AppModule2 { }
當我啓動的應用程序(使用Chrome 57),錯誤的是:
Error: Can't resolve all parameters for HomeComponent: (?).
Evaluating http://localhost:3000/src/main.ts
Loading myapp
at syntaxError (http://localhost:3000/jspm_packages/npm/@angular/[email protected]/bundles/compiler.umd.js:1513:34) [<root>]
at CompileMetadataResolver._getDependenciesMetadata (http://localhost:3000/jspm_packages/npm/@angular/[email protected]/bundles/compiler.umd.js:14363:35) [<root>]
at CompileMetadataResolver._getTypeMetadata (http://localhost:3000/jspm_packages/npm/@angular/[email protected]/bundles/compiler.umd.js:14231:26) [<root>]
at CompileMetadataResolver.getNonNormalizedDirectiveMetadata (http://localhost:3000/jspm_packages/npm/@angular/[email protected]/bundles/compiler.umd.js:13840:24) [<root>]
at CompileMetadataResolver._getEntryComponentMetadata (http://localhost:3000/jspm_packages/npm/@angular/[email protected]/bundles/compiler.umd.js:14484:45) [<root>]
at eval (http://localhost:3000/jspm_packages/npm/@angular/[email protected]/bundles/compiler.umd.js:14067:108) [<root>]
at Array.map (native) [<root>]
at CompileMetadataResolver.getNgModuleMetadata (http://localhost:3000/jspm_packages/npm/@angular/[email protected]/bundles/compiler.umd.js:14067:73) [<root>]
at JitCompiler._loadModules (http://localhost:3000/jspm_packages/npm/@angular/[email protected]/bundles/compiler.umd.js:25144:64) [<root>]
at JitCompiler._compileModuleAndComponents (http://localhost:3000/jspm_packages/npm/@angular/[email protected]/bundles/compiler.umd.js:25103:52) [<root>]
at JitCompiler.compileModuleAsync (http://localhost:3000/jspm_packages/npm/@angular/[email protected]/bundles/compiler.umd.js:25065:21) [<root>]
at PlatformRef_._bootstrapModuleWithZone (http://localhost:3000/jspm_packages/npm/@angular/[email protected]/bundles/core.umd.js:4793:25) [<root>]
at PlatformRef_.bootstrapModule (http://localhost:3000/jspm_packages/npm/@angular/[email protected]/bundles/core.umd.js:4779:21) [<root>]
at Object.execute (http://localhost:3000/src/main.ts!transpiled:19:65) [<root>]
如果刪除的Http
注射在HomeComponent
噸他應用程序加載成功。
我tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [ "es2015", "dom" ],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
}
}
這是因爲你缺少@Injectable()裝飾器?來源:https://gist.github.com/gsans/d020de5f0fbe56a22c824e1158ba7ec8#file-mycomponent-ts – floor
@floor問題是與一個角度的服務,我應該在這裏添加'@Injectable()'代碼? – Roberto
嘗試:從'@ angular/common'導入{CommonModule,Injectable};並將@Injectable()放在主組件導出之上。 – floor