I am sharing code from my angular 8 application.(我正在从我的angular 8应用程序共享代码。)
As you can see below there are two classes.(如您在下面看到的,有两个类。) Base service class and child service class that derives from the base service class.(基本服务类和从基本服务类派生的子服务类。) As you can also see the child class is using the base class property like this ${this._baseUrl}.(您还可以看到子类正在使用基类属性,例如$ {this._baseUrl}。) Could somebody tell me what does this notation mean ${} ?(有人能告诉我这个符号是什么意思$ {}吗?)
Base Service(基础服务)
@Injectable()
export class BaseService {
_baseUrl: string = environment.apiBaseUrl;
constructor(protected httpClient: HttpClient, protected _injector: Injector){}
protected getRequestHeaders(): { headers: HttpHeaders | { [header: string]: string | string[]; } } {
let headers = new HttpHeaders({
'Content-Type': 'application/json',
'Accept': `application/json, text/plain, */*`,
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET,DELETE,OPTIONS'
});
return { headers: headers };
}
protected getBaseUrl() : string {
return this._baseUrl;
}
}
cities service(城市服务)
@Injectable()
export class CitiesEndpoint extends BaseService {
constructor(_httpClient: HttpClient, _injector: Injector) {
super(_httpClient, _injector);
}
// city api endpoints
getAllCities() {
return `${this._baseUrl}/api/cities`;
}
deleteCity(id) {
return `${this._baseUrl}/api/cities/delete-city//${id}`;
}
}
ask by Tom translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…