Recently i am learn the angular2's http client and i have finished the demo with angular-in-memory-web-api
.Now i want to use http.get to request the local json data ,but browser tell me zone.js:1980 GET http://localhost:4200/app/hero.json 404 (Not Found)
,after read the related posts of Angular2 404 Not Found for URL: http://localhost/WebApi2/api/hero and the simliar one of angular get, i have removed the 'angular-in-memory-web-api'
,InMemoryWebApiModule.forRoot(HeroData)
and the related file from my project ,but the issue of 404 (Not Found)
is stil exists,the key code is following:
//app.module.ts
@NgModule({
imports: [
BrowserModule,
FormsModule,
HttpModule,
JsonpModule,
],
declarations: [
AppComponent,
HeroListComponent,
HeroListPromiseComponent,
WikiComponent,
WikiSmartComponent
],
providers: [ requestOptionsProvider ],
bootstrap: [ AppComponent ]
})
export class AppModule {}
//hero.service.tsenter code here
@Injectable()
export class HeroService {
private heroesUrl = 'app/hero.json';
constructor (private http: Http) {}
getHeroes(): Observable<Hero[]> {
// debugger;
return this.http.get(this.heroesUrl)
.map(this.extractData)
.catch(this.handleError);
}
private extractData(res: Response) {
// http.get or http.post return the json obj
let body = res.json();
return body.data || { };
}
if you want all code, i have pushed it to my github.this is the address
anyone can help me please