Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to concat url in Angular 6?

I have common-class has commonUrl, this commonUrl i used in category.service.ts but it not concat in service.ts how to concat this commonUrl in angular 6?

common-class.ts

export class CommonClass {
  constructor(public commonUrl : string = 'http://localhost:3000'){};
}

category.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());
}

2 Answers

I'd advice you to use a string literal. Using `, resulting in `${this.commonUrlObj.commonUrl}/saveNewCategory`

like image 74
Arne Avatar answered Jan 29 '26 07:01

Arne


remove single quotes from 'this.commonUrlObj.commonUrl'

saveNewCategory(formData){
  return this.http.post(this.commonUrlObj.commonUrl+'/saveNewCategory',formData).map((res: any) => res.json());
}
like image 27
Krishna Rathore Avatar answered Jan 29 '26 05:01

Krishna Rathore



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!