[英]Angular 5 remove child component from parent component
當用戶單擊子組件中存在的關閉按鈕時,我想從其父組件中刪除一個子組件。 我的父級組件中有3個組件。
<app-header></app-header>
<app-map></app-map>
<app-rules *ngIf="selectedId"></app-rules>
我試圖在單擊內部的關閉按鈕時將selectedId的值更新為undefined。 但它不會采用更新的值並關閉組件。
您的問題可能是* ngIf期望為布爾狀態。 驗證數字時,undefined是無效狀態。 你必須實現一個比較然后
// selectedId is a number
<app-rules *ngIf="selectedId > 0"></app-rules>
要么
// selectedId is a string
<app-rules *ngIf="selectedId !== undefined"></app-rules>
// in case of a string this is also possible
<app-rules *ngIf="selectedId"></app-rules>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.