我在处理此.json时遇到麻烦,它一直在说“对象没有 支持属性或方法“ json””。我是否必须添加其他导入 为了这个?指导我,谢谢您将来的回答。
import { HttpClientModule, HttpClient } from '@angular/common/http';
import { map } from 'rxjs/operators';
import { Response } from "@angular/http";
import { Injectable } from '@angular/core';
/*
Generated class for the DataServiceProvider provider.
See https://angular.io/guide/dependency-injection for more info on
providers
and Angular DI.
*/
@Injectable()
export class DataServiceProvider {
constructor(private http: HttpClient) {
console.log('Hello DataServiceProvider Provider');
}
getMenus(){
return this.http.get('assets/data/menus.json')
.pipe(map((response:Response)=>response.json()));
}
}
答案 0 :(得分:2)
您不需要.json。不再需要自己调用此函数。
return this.http.get('assets/data/menus.json')
.pipe(map((response:Response)=>response));