我对Angular非常陌生,正在为几个概念而挣扎。我有一个子组件:
<ng-template #days>
<div *ngFor="let day of mappedDays">
<job-day-listing [jobDay]="day" [canEdit]="canEdit" (vehicleSelectChange)="vehicleSelectChanged($event)" (employeeSelectChange)="employeeSelectChanged($event)" (click)="clearSelection()"></job-day-listing>
</div>
</ng-template>
我需要访问孩子的 typescript 中的“mappedDays”,但我似乎做不到。
我试着在孩子中创建一个输入变量:
@Input() mappedDays: JobDayMapping[];
mappedDays: JobDayMapping[];
在html中:
<ng-template #days>
<div *ngFor="let day of mappedDays">
<span>[mappedDays]="mappedDays"</span>
<job-day-listing [jobDay]="day" [canEdit]="canEdit" (vehicleSelectChange)="vehicleSelectChanged($event)" (employeeSelectChange)="employeeSelectChanged($event)" (click)="clearSelection()"></job-day-listing>
</div>
</ng-template>
然后,我尝试在数组上调用forEach,但在mappedDays数组上收到一个“undefined”错误:
this.mappedDays.forEach(md => {
md.addEditButtonSelected = false;
});
我需要服务吗?
1条答案
按热度按时间epggiuax1#
这种方法很好(通过
@Input()
绑定将mappedDays
传递给子进程),但是代码中存在一些错误:您的当前代码
<span>
标记[mappedDays]
属性在span的开始标记(>
)的错误一侧,因此它将在span中作为文本列出。以下方法应该有效:
x一个一个一个一个x一个一个二个x