<a [routerLink]="..."/>
<a routerLink="..."/>
I see in the tutorial they've used two types of syntaxes for routerLink attribute.
I cannot find any documents which tell the differences between them.
This is something that is very important to know about Angular! when you are using [] around you're property it means that it equal to some variable from the script and if it is not covered by this [] is just the string is equal to
this is the two ways to get TS variables to the template
ts
export class DemoComponent implements OnInit {
someLinkFromTheTS:string = "/home";
}
html
<a [routerLink]="someLinkFromTheTS"/>
<a routerLink="{{someLinkFromTheTS}}"/>
And if you do not want to use variables
<a routerLink="/home"/>
The brackets tell Angular to evaluate the template expression. If you omit the brackets, Angular treats the string as a constant and initializes the target property with that string.
this is a very important concept
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments