Reputation: 1943
I am learning Angular 2 with Typescript . I came across an example which has quite confused me . Here it goes
In
component.ts
getValidation(state:any, thingName?: string) {
let thing: string = state.path || thingName;
let messages : string[] = [];
messages.push(`You must enter a **${thing}**`);
}
What is the significance of using $
and {}
in the above example, until now I always used this.thing to use any variable?
Upvotes: 1
Views: 3411
Reputation: 5454
What you're referring to our template literals in JavaScript (TypeScript is a typed superset of JavaScript*). It's a way to refer to variable defined outside of everything you have defined within the backticks. So ${variable}
is simply the way to reference it is all.
Upvotes: 5