import { Component, OnInit } from '@angular/core';
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
configUrl = '/config.json';
getConfig() {
return this.http.get(this.configUrl);
}
@Component({
selector: 'app-rest',
templateUrl: './rest.component.html',
styleUrls: ['./rest.component.css']
})
@Injectable()
export class RestComponent {
constructor(private http: HttpClient) { }
}
我已经在config.json
{
"heroesUrl": "http://xx.xxx.xx.xxx:3001/getAllData"
}
我正在使用另一个文件中的heroesUrl调用其余的api,并且我已将文件链接到主文件夹中,但是我遇到了错误,请帮我帮忙,以角方式调用其余的api
答案 0 :(得分:0)
将http.get放入组件代码中,
export class RestComponent {
constructor(private http: HttpClient) { }
getConfig() {
return this.http.get(this.configUrl);
}
}