angular - When would you surround routerLink in square brackets? -
the angular 2 cheat sheet shows examples of routerlink
both , without square brackets in templates:
<a routerlink="/path"> <a [routerlink]="[ '/path', routeparam ]"> <a [routerlink]="[ '/path', { matrixparam: 'value' } ]"> <a [routerlink]="[ '/path' ]" [queryparams]="{ page: 1 }"> <a [routerlink]="[ '/path' ]" fragment="anchor">
what's difference in functionality?
when put square brackets around routerlink
(or angular 2 binding) evaluate pass javascript expression. if don't put square brackets around routerlink
take pass literal string.
so if want pass array routerlink or evaluate variable have use square brackets. if want pass string either do
<a routerlink="/path">
or
<a [routerlink]="'/path'">
Comments
Post a Comment