How to concat url in Angular 6?

string concatenation in angular 6 html
angular 4 concat string
angular concat string
angular concatenate string and variable
angular url builder
angular get url segments
html concatenate string and variable
concat 2 string in angular

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

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

Concatenate a variable in a string so as to form a URL, Concatenate a variable in a string so as to form a URL · angular typescript. I'm trying to consume an API which has to be specific for given users  In Angular 6, you can use the Interpolation technique to concatenate a string with a variable inside an HTML element tag. Here’s an example. I have a table inside my application template. The table rows are populate with data extracted from a JSON array, declared in my component class.

remove single quotes from 'this.commonUrlObj.commonUrl'

saveNewCategory(formData){
  return this.http.post(this.commonUrlObj.commonUrl+'/saveNewCategory',formData).map((res: any) => res.json());
}

Concatenate String with Variable inside HTML element tag in , In Angular 6, you can use Interpolation to concatenate a string with a variable inside an HTML element tag. How to Concat string in AngularJs | Join Strings Example. Let us go step by step to create an example to join strings in AngularJs using JavaScript Concat() method-JavaScript Part . JavaScript Part Contains the following part as below –

Please remove the single quotes and it should work.

return this.http.post(this.commonUrlObj.commonUrl+'/saveNewCategory',formData).map((res: any) => res.json());

TypeScript - String concat(), TypeScript - String concat() - This method adds two or more strings and returns a new single string. CLI tool for Angular. Contribute to angular/angular-cli development by creating an account on GitHub. This should fix errors like the one below for 0.6.0: ``` URL Loader Invalid Options options['name'] should NOT have additional properties options.limit should be number ```

UrlSegment, A UrlSegment is a part of a URL between the two slashes. It contains a path and the matrix parameters associated with the segment. Constructor  Angular is a platform for building mobile and desktop web applications. Join the community of millions of developers who build compelling user interfaces with Angular. Help JioDev by taking a 1 minute survey !

Location, The given URL path. query, string. Query parameters. Optional. Default is '' . Returns. An Angular service to provide URL helpers. Contribute to meanie/angular-url development by creating an account on GitHub.

AngularJS to Angular concepts: Quick reference, that it can replace the binding expression with the appropriate URL before the the many parts of the application merge, which can cause unexpected results. Query parameters in Angular allow for passing optional parameters across any route in the application. Query params are different from regular route parameters, which are only available on one route and are not optional (e.g.: /product/:id ). Let’s see how to work with query parameters. Let’s use a very simple example where we want to route

Comments
  • i think it should be return this.http.post(this.commonUrlObj.commonUrl +'/saveNewCategory' + formData).map((res: any) => res.json());
  • Possible duplicate of JS strings "+" vs concat method
  • using the above template literal is the recommended way. If you use +, it will result in a code smell defect if you are running a tool like Sonar.