admin管理员组文章数量:1287849
I have mon-class has monUrl, this monUrl i used in category.service.ts but it not concat in service.ts how to concat this monUrl in angular 6?
mon-class.ts
export class CommonClass {
constructor(public monUrl : string = 'http://localhost:3000'){};
}
category.service.ts
import { CommonClass } from '../classes/mon-class';
monUrlObj : CommonClass = new CommonClass();
saveNewCategory(formData){
return this.http.post('thismonUrlObjmonUrl'+''+'/saveNewCategory',formData).map((res: any) => res.json());
}
getCategoryDetails(param){
return this.http.post('thismonUrlObjmonUrl'+''+'getCategoryDetails',param).map((res: any) => res.json());
}
I have mon-class has monUrl, this monUrl i used in category.service.ts but it not concat in service.ts how to concat this monUrl in angular 6?
mon-class.ts
export class CommonClass {
constructor(public monUrl : string = 'http://localhost:3000'){};
}
category.service.ts
import { CommonClass } from '../classes/mon-class';
monUrlObj : CommonClass = new CommonClass();
saveNewCategory(formData){
return this.http.post('this.monUrlObj.monUrl'+''+'/saveNewCategory',formData).map((res: any) => res.json());
}
getCategoryDetails(param){
return this.http.post('this.monUrlObj.monUrl'+''+'getCategoryDetails',param).map((res: any) => res.json());
}
Share
Improve this question
edited Sep 25, 2018 at 9:05
asked Sep 25, 2018 at 8:48
user10411207user10411207
2
-
2
i think it should be
return this.http.post(this.monUrlObj.monUrl +'/saveNewCategory' + formData).map((res: any) => res.json());
– Lia Commented Sep 25, 2018 at 8:52 - 1 Possible duplicate of JS strings "+" vs concat method – Jota.Toledo Commented Sep 25, 2018 at 9:00
3 Answers
Reset to default 7I'd advice you to use a string literal. Using `
, resulting in `${this.monUrlObj.monUrl}/saveNewCategory`
remove single quotes
from 'this.monUrlObj.monUrl'
saveNewCategory(formData){
return this.http.post(this.monUrlObj.monUrl+'/saveNewCategory',formData).map((res: any) => res.json());
}
Please remove the single quotes and it should work.
return this.http.post(this.monUrlObj.monUrl+'/saveNewCategory',formData).map((res: any) => res.json());
本文标签: javascriptHow to concat url in Angular 6Stack Overflow
版权声明:本文标题:javascript - How to concat url in Angular 6? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741320873a2372195.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论