0
product.service.ts文件:Angular2服務調用JSON路徑
import { Injectable } from '@angular/core';
import { Http , Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/do';
import { IProduct } from './product';
@Injectable()
export class ProductService {
private _producturl='src/products.json';
constructor(private _http: Http){}
getproducts(): Observable<IProduct[]> {
return this._http.get(this._producturl)
.map((response: Response) => <IProduct[]> response.json())
.do(data => console.log(JSON.stringify(data)));
}
}
請找到文件夾結構
下面所附截圖,但是當頁面加載它顯示了我一個錯誤: 區.js文件:2744 GET http://0.0.0.0:4200/src/products.json 404(未找到)
感謝哥們:)現在工作正常 –