我有公共(public)类有commonUrl,这个commonUrl我在category.service.ts中使用,但它没有在service.ts中连接,如何在 Angular 6中连接这个commonUrl?
common-class.ts
export class CommonClass {
constructor(public commonUrl : string = 'http://localhost:3000'){};
}
类别.service.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`
关于javascript - 如何在 Angular 6 中连接 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52494098/