'what does the symbol '$' mean in angular?
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;
}
Solution 1:[1]
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`;
Solution 2:[2]
${} are used as placeholders in a template string, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
Solution 3:[3]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Padmapriya Vishnuvardhan |
Solution 3 | Kaan AteÅŸel |