角度2:404(未找到)

时间:2017-07-05 14:26:52

标签: json angular

我使用angular-cli创建了我的应用 我编写了服务GameService来获取json文件中的数据:

import { Injectable } from '@angular/core';
import { Http, Response, RequestOptions, Headers } from '@angular/http';
import 'rxjs/add/operator/map';

@Injectable()
export class GameService {

  constructor(private http: Http) { }

  getGames() {
    let headers = new Headers({ 'Content-Type': 'application/json' });
    let options = new RequestOptions({ headers: headers });
    return this.http.get('app/shared/games.json', options)
        .map((res: Response) => res.json());
  }
}

我也创建了模型Game

export class Game {
    title: String;
    image: String;
    cost: String;
}

我在AppModule

中导入了服务和模型
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpModule } from '@angular/http';

import { AppComponent } from './app.component';

import { GameService } from './shared/services/game.service';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    HttpModule
  ],
  providers: [
    GameService
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

加载应用程序我收到错误:

GET http://localhost:4200/app/shared/games.json 404 (Not Found)

以下是结构应用:
enter image description here

我不明白我在哪里做错了。我在stackoverlow上搜索并看到了很多问题和答案,但它没有帮助 请帮我。

0 个答案:

没有答案