📜  带有 httpclient 的角度加载 json 文件 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:08.432000             🧑  作者: Mango

代码示例1
import { HttpClient } from '@angular/common/http'; 
import { Observable } from 'rxjs';

@Injectable()
export class AppSettingsService {

   constructor(private http: HttpClient) {
        this.getJSON().subscribe(data => {
            console.log(data);
        });
    }

    public getJSON(): Observable {
        return this.http.get("./assets/mydata.json");
    }
}