css - Can't assign [ngClass] to Angular components generated by *ngFor loop -
i'm trying follow an example showing how bind class active component when it's clicked. when execute code based on markup below
<div *ngfor="let menu of menus;" [id]="menu.id" (click)="onclick($event,menu.link)" [ngclass]="'active':menu.active" class="navigator"> {{menu.title}} </div> i following error. nb - there's onclick(...) method in component , @ moment commented out contents. error seems purely related markup (unless need declare in component, array or such). @ least far i've seen examples while googlearching issue.
uncaught error: template parse errors:
parser error: unexpected token ':' @ column 9 in ['active':menu.active] in ng:///appmodule/navigatorcomponent.html@11:9 ("
[id]="menu.id"
(click)="onclick($event,menu.link)"
[error ->][ngclass]="'active':menu.active"
class="navigator">
{{menu.title}}
"): ng:///appmodule/navigatorcomponent.html@11:9
what missing?
'active':menu.active isn't valid expression.
user either object literal syntax
[ngclass]="{'active':menu.active}" or string syntax
[ngclass]="menu.active ? 'active' : null" or
[class.active]="menu.active"
Comments
Post a Comment