I'm learning Angular 2 and I came across a few new things. I used ScratchJS extension of Chrome browser to learn TypeScript. While doing that, this is what I did for a backtick (`) string:
let user='user';
let msg=`Welcome ${user}!
I can write multi-line string.
This is awesome!
`;
console.log(msg);
As you can see, this is how the variable user is used in the string. But when I do the same thing in an Angular 2 project, it's a bit different (and doing things like above will throw an error). For my dummy Angular 2 project, I made a simple component:
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() {
}
}
This works. But here, I'm using string interpolation using:
{{}}
instead of:
${}
And if I use that, it will throw an error. I know I understood some facts wrong. But can anyone explain what is it?