由于 ngIf 而隐藏组件的引用
keep reference of components hidden due to ngIf
我有一个问题 div 使用 ngFor 生成一些子组件。
这些子组件具有数据输入字段。当用户在这些字段中输入数据并单击下一步按钮时,问题 div 被 ngIf 隐藏,预览 div 出现。当再次按下后退按钮时,预览 div 会用 ngIf 隐藏,问题 div 会出现。但是因为问题 div 中的子组件被再次创建,所以来自输入字段的数据消失了。以下是我的 html
<!-- questions
div-->
<div class="questions activity_screen" *ngIf="showquestions">
<div *ngFor="let component of components;let i=index">
<app-termhost #cmp [term] = component [title]="component.title" [Qnumber]="i+1"></app-termhost>
</div>
<a class="submit_button" (click)="getdata()">Submit</a>
</div>
<!-- preview div-->
<div style="width: 100%;height: 100%;display: flex;align-content: center;justify-content: center" class="preivew" *ngIf="showpdf">
<button (click)="goback()">go back</button>
</div>
如何保持这些组件的先前状态,以便在按下后退按钮后再次出现问题 div 后数据不会丢失!
尝试使用 hidden 属性 而不是 *ngIf,hidden 将仅与 css 一起播放,但 *ngIf 将完全删除元素 :
[hidden]="condition"
我有一个问题 div 使用 ngFor 生成一些子组件。 这些子组件具有数据输入字段。当用户在这些字段中输入数据并单击下一步按钮时,问题 div 被 ngIf 隐藏,预览 div 出现。当再次按下后退按钮时,预览 div 会用 ngIf 隐藏,问题 div 会出现。但是因为问题 div 中的子组件被再次创建,所以来自输入字段的数据消失了。以下是我的 html
<!-- questions
div-->
<div class="questions activity_screen" *ngIf="showquestions">
<div *ngFor="let component of components;let i=index">
<app-termhost #cmp [term] = component [title]="component.title" [Qnumber]="i+1"></app-termhost>
</div>
<a class="submit_button" (click)="getdata()">Submit</a>
</div>
<!-- preview div-->
<div style="width: 100%;height: 100%;display: flex;align-content: center;justify-content: center" class="preivew" *ngIf="showpdf">
<button (click)="goback()">go back</button>
</div>
如何保持这些组件的先前状态,以便在按下后退按钮后再次出现问题 div 后数据不会丢失!
尝试使用 hidden 属性 而不是 *ngIf,hidden 将仅与 css 一起播放,但 *ngIf 将完全删除元素 :
[hidden]="condition"