angular - Declare variable in ngFor -
in angular2 project need present matrix. current code:
<tr *ngfor="let worker of workers"> <td class="{{worker.fired ? 'fired-worker':''}}">{{worker.lastname}}<br>{{worker.firstname}}</td> <td *ngfor="let course of courses;" class="sk-table-sub-header"> <div *ngif="course.isgeneric"> <div class="col-xs-6" sc-dc [sc-dc-date]="matrix[worker.id][course.id].expiration"> <date-picker (ondatechanged)="ondatechanged($event, worker, course, 'genericstartdate')" [date]="matrix[worker.id][course.id].genericstartdate></date-picker> </div> <div class="col-xs-6 training-table-rounded-cell" sc-dc [sc-dc-date]="matrix[worker.id][course.id].expiration"> <date-picker (ondatechanged)="ondatechanged($event, worker, course, 'expiration')" [date]="matrix[worker.id][course.id].expiration" ></date-picker> </div> </div> ...
as can see use matrix[worker.id][course.id].expiration
multiple times. try avoid declaring variable this:
<td *ngfor="let course of courses; let item = matrix[worker.id][course.id]" ...>
but parse error:
parser error: unexpected token [, expected identifier, keyword, or string @ column 44 in [ngfor let course of courses; let = matrix[worker.id][course.id]] in trainingplancomponent@44:20 ("r.fired ? 'fired-worker':''}}">{{worker.lastname}}<br>{{worker.firstname}}</td>
is there way achieve intent?
thanks lot
you can't assign arbitrary values template variables.
- template variables can refer elements or components added
exportas
references can assigned template variables#xxx="ngform"
- local variables created directives
index
ngfor
can assigned
there open issue support use case it's unclear if , when supported.
as workaround might consider wrapping part of template own component , pass values @input()
s
Comments
Post a Comment