如何创建将在我的服务中使用这种类型的url的方法?
这是我挥舞自如的/api/campaign/{uuid}/activation/
的api网址,但是我不确定如何在服务中使用它。
// i guess this has to change
private stopCampaignUrl = environment.apiUrl + '/campaign/activation/';
//this will put uuid at the end of url for now
stopCampaign(uuid, stopModel: StopCampaignModel) {
return this.http.put(`${this.stopCampaignUrl}${uuid}`, stopModel);
}
或者最好的解决方案是将{{uuid}}
移至网址末尾?
答案 0 :(得分:2)
请考虑编写一种单独的方法来从uui中获取url并将其用于stopCampaign
private getCampageUrl(uuid){
return environment.apiUrl + '/campaign/'+uuid+'/activation/';
}
答案 1 :(得分:1)
您可以这样做:
for
答案 2 :(得分:1)
我为您提供功能:
R.version
_
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 5.0
year 2018
month 04
day 23
svn rev 74626
language R
version.string R version 3.5.0 (2018-04-23)
nickname Joy in Playing
像这样使用它:
function stringFormat(format: string, ...args: string[]): string {
return format.replace(/{(\d+)}/g, (match, number) => {
return typeof args[number] != "undefined" ? args[number] : match;
});
}
stringFormat用uuid值替换{0}。更多示例:
private stopCampaignUrl = '/api/campaign/{0}/activation/';
stopCampaign(uuid, stopModel: StopCampaignModel) {
return this.http.put(stringFormat(stopCampaignUrl ,uuid), stopModel);
}