簡體   English   中英

當父項上的下一個項目的選擇器上的ngIf具有相同的變量值時,不會破壞角型子組件

[英]Angular child component not destroyed when next item on parent has same variable value for ngIf on selector

我有一個名為currTab的數字變量,用於在子組件模板上通過三個div進行制表。 在父組件模板上選擇tab時,子組件將打開並帶有前一個實例的值。 打開時的默認值應為currTab = 1,但如果選擇2或3,則從父級打開的下一個子級將具有該值。 我嘗試通過ngOnInit和大多數其他生命周期事件通過@Input currItem設置默認值,但是它沒有任何效果。 我有另一個@Input稱為property,它可以很好地傳遞。 每次在父窗體上激活選擇器時,子組件都會反映正確的“屬性”,而不是默認的“ currTab”。

子組件(模板電視屬性)

  <input class="propertyTab" type="button" (click)="currTab = 1" value="Main View" [disabled]="currTab == 1" > <input class=minMaxTab" type="button" (click)="currTab = 2" value="Min Max Values" [disabled]="currTab == 2" > <input class="propertyTab" type"button" (click)="currTab = 3" value=" Lookup Values" [disabled]="currTab == 3" > 

父模板

 <div class="itemFrame" *ngIf="currItemType !== ''"> <template-tv-property [property]="currItem" [currTab]="1" (saveCurrentProperty)="saveCurrentItem($event)" [choiceBoxSize]="propertyChoicesListBoxSize" *ngIf="currItemType === 'property'" ></template-tv-property> <template-tv-part [part]="currItem" *ngIf="currItemType === 'part'"></template-tv-part> <template-tv-infogroup [infogroup]="currItem" *ngIf="currItemType === 'infoGroup'" ></template-tv-infogroup> <template-tv-grid [grid]="currItem" *ngIf="currItemType === 'grid'" ></template-tv-grid> <template-tv-signature-group [signatureGroup]="currItem" *ngIf="currItemType === 'signatureGroup'"></template-tv-signature-group> <template-tv-signature [signature]="currItem" *ngIf="currItemType === 'signature'"></template-tv-signature> </div> 

畢竟這個問題已經得到回答。 我第一次搜索沒有找到它。

銷毀並重新加載子組件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM