Reputation: 31
What does mean by $ in ${some_var}
search(term:string) {
let promise = new Promise((resolve, reject) => {
let apiURL = `${this.apiRoot}?term=${term}&media=music&limit=20`;
this.http.get(apiURL)
.toPromise()
.then(
res => { // Success
console.log(res.json());
resolve();
}
);
});
return promise;
}
Upvotes: 2
Views: 8449
Reputation: 470
There are other usage of $ sign:
<li *ngFor="let hero of heroes$ | async" >
in this case, The $ is a convention that indicates heroes$ is an Observable, not an array.
Upvotes: 2
Reputation: 879
Thats template literals to use for string interpolation.
Earlier we use below code for string concatenation
var user ="lokesh"
var testStr = "my name is "+ user
Now in typescript and in ECMA6 that can be used like this
var user ="lokesh"
var testStr = `my name is ${user}`
In your case old version
let apiURL = this.apiRoot + '?term='+term+'&media=music&limit=20';
typescript and ECMA6
let apiURL = `${this.apiRoot}?term=${term}&media=music&limit=20`;
Upvotes: 5
Reputation: 2166
${} are used as placeholders in a template string, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
Upvotes: 0