Javascript 如何在Angular 6中连接url?
我有一个公共类有commonUrl,这个commonUrl是我在category.service.ts中使用的,但它不是在service.ts中使用的concat。如何在第6节中使用这个commonUrl 通用类Javascript 如何在Angular 6中连接url?,javascript,string,typescript,Javascript,String,Typescript,我有一个公共类有commonUrl,这个commonUrl是我在category.service.ts中使用的,但它不是在service.ts中使用的concat。如何在第6节中使用这个commonUrl 通用类 export class CommonClass { constructor(public commonUrl : string = 'http://localhost:3000'){}; } 类别.服务.ts import { CommonClass } from '../cl
export class CommonClass {
constructor(public commonUrl : string = 'http://localhost:3000'){};
}
类别.服务.ts
import { CommonClass } from '../classes/common-class';
commonUrlObj : CommonClass = new CommonClass();
saveNewCategory(formData){
return this.http.post('this.commonUrlObj.commonUrl'+''+'/saveNewCategory',formData).map((res: any) => res.json());
}
getCategoryDetails(param){
return this.http.post('this.commonUrlObj.commonUrl'+''+'getCategoryDetails',param).map((res: any) => res.json());
}
从
'this.commonUrlObj.commonUrl'中删除单引号
saveNewCategory(formData){
return this.http.post(this.commonUrlObj.commonUrl+'/saveNewCategory',formData).map((res: any) => res.json());
}
我建议您使用字符串文字。使用
`
,产生`${this.commonUrlObj.commonUrl}/saveNewCategory`
请删除单引号,它应该可以工作
return this.http.post(this.commonUrlObj.commonUrl+'/saveNewCategory',formData).map((res: any) => res.json());
我认为应该
返回this.http.post(this.commonUrlObj.commonUrl+'/saveNewCategory'+formData).map((res:any)=>res.json())代码>建议使用上述模板文本的可能重复。如果您使用+
,如果您运行的是Sonar之类的工具,则会导致代码气味缺陷。