在angularJS中,我们可以在ng-repeat中使用$ parent访问数据。 Angular 7中有等效功能吗?下面是场景
我的模型类:-
export class Question {
Sections : Array<Section>;
IsArchived : boolean;
}
export class Section{
Name : string;
}
HTML:-
<div *ngFor="let section of Question.Sections">
{{section.Name}}
<!--Want to access parent here-->
<span *ngIf="$parent.IsArchived"> This is archived</span>
</div>
答案 0 :(得分:2)
没有与angularjs中等效的$ parent,但是您可以在ngFor内简单地使用父对象
<div *ngFor="let section of Question.Sections">
{{section.Name}}
<span *ngIf="Question.IsArchived"> This is archived</span>
</div>