I am trying to use angular 2 Http service but I am getting
Can't resolve all parameters for AppComponent: (?)
Which has this signature
constructor(public http:Http){ }
I tracked the problem down to declaring the providers for Http.
In the angular 2 quickstart they say
In this demo, we register providers by importing other NgModules to our root NgModule.
But I already have
@NgModule({
imports: [ BrowserModule, HttpModule, FormsModule ],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
So, I understand the providers should be fine.
In the code documentation for file http.d.ts
I find this:
* import {Http, HTTP_PROVIDERS} from '@angular/http';
But when I try to write this, I get that HTTP_PROVIDERS
does not exist (I guess it is before GA)
The only way I can solve this error is by adding @Inject(Http)
in the signature.
How can I make it work without adding @Inject(Http)
in the signature?
This is my systemjs config
<script>
System.config({
transpiler: 'typescript',
map: {
'@angular/core': './node_modules/@angular/core/bundles/core.umd.js',
'@angular/platform-browser-dynamic': './node_modules/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/platform-browser': './node_modules/@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/compiler': './node_modules/@angular/compiler/bundles/compiler.umd.js',
'@angular/common': './node_modules/@angular/common/bundles/common.umd.js',
'@angular/http': './node_modules/@angular/http/bundles/http.umd.js',
'@angular/forms': './node_modules/@angular/forms/bundles/forms.umd.js',
'rxjs': './node_modules/rxjs'
},
packages: {
'./app': {
defaultExtension: 'ts'
},
'@angular/http':{
defaultExtension:'ts'
},
'rxjs': {
defaultExtension: 'js'
}
}
})
System.import('./app/main.ts').catch(function (err) {
console.error(err);
});
</script>
This is my tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
}
}
You can see all my code at https://github.com/GuyMograbi/angular2-simple-setup