I'm using Angular 2.2 and running into problems with what should be a very simple HTTP request using @angular/http
EDIT:
Error: No provider for ConnectionBackend
I thought solved this error by importing ConnectionBackend
from @angular/http
and adding as a Provider
in app.module.ts
.
But on stop and start of the server I get this error.
Type 'typeof ConnectionBackend' is not assignable to type 'Provider'
So I removed ConnectionBackend
from import and Provider.
I have tried the following to no avail:
Angular2/http Exception no ConnectionBackend
No provider for ConnectionBackend
Angular 2 : No provider for ConnectionBackend
app.module.ts:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { CustomService } from './custom.service';
@NgModule({
imports: [
BrowserModule,
HttpModule
],
declarations: [
AppComponent
],
providers: [
CustomService
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
custom.service.ts:
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import 'rxjs/Rx';
@Injectable()
export class CustomService{
constructor( private _http: Http){}
getJson() {
return this._http.get('app/file.json')
.toPromise()
.then(response => response.json())
}
}
app/file.json:
[
{"id": 1, "name": "test1"},
{"id": 2, "name": "test2"},
{"id": 3, "name": "test3"},
{"id": 4, "name": "test4"},
{"id": 5, "name": "test5"}
]
package.json angular dependencies:
"dependencies": {
"@angular/common": "~2.2.0",
"@angular/compiler": "~2.2.0",
"@angular/core": "~2.2.0",
"@angular/forms": "~2.2.0",
"@angular/http": "~2.2.0",
"@angular/platform-browser": "~2.2.0",
"@angular/platform-browser-dynamic": "~2.2.0",
"@angular/router": "~3.2.0",
"@angular/upgrade": "~2.2.0",
I can't be the only person experiencing this issue. I've started over making a very basic application, but I get the same error.