Greetings! Currently, I am delving into the world of Angular 2 and have stumbled upon some interesting discoveries. To enhance my knowledge of TypeScript, I decided to utilize the ScratchJS extension on the Chrome browser. During this exploration, I experimented with backtick (`) strings in the following manner:
let user='user';
let msg=`Welcome ${user}!
I can write multi-line string.
This is awesome!
`;
console.log(msg);
As illustrated above, the variable "user" is dynamically incorporated into the string using template literals. However, when attempting a similar approach within an Angular 2 project, I encountered a slight deviation (resulting in errors if implemented as before). Within my simplistic Angular 2 component, the structure was as follows:
import { Component} from '@angular/core';
@Component({
selector: 'app-user',
template: `
Hi, {{user}}
I can write multi-line string.
This is awesome!
`,
styles: []
})
export class UserComponent {
user:string='John Doe';
constructor() {
}
}
Although this method proved successful, I noticed that I employed string interpolation using "{{}}" instead of "${}". Utilizing "${}" resulted in errors, prompting me to acknowledge a misconception in my understanding. Could someone kindly shed light on this issue?