[英]ngOnDestroy not fired after button click in angular
HTML…………
<div class="form-group">
<button type="submit"
value="submit"
class="btn btn-secondary btn-float">Upload</button>
</div>
</div>
TS文件…………
export class testComponent implements OnDestroy {
ngOnDestroy() {
console.log("Fired ngOnDestroy");
}
onClickSubmit() {
this.subscription = this.service
.create(test, url)
.subscribe(
res => {
console.log('HTTP response', res)
},
err => {
console.log("Error", err)
},
() => console.log('HTTP request completed.')
);
}
}
我試圖在我的 ngondestroy() 沒有觸發之后點擊按鈕調用服務我不知道為什么它不起作用
當組件從 DOM 中移除時,框架會調用ngOnDestroy
。
您的示例中沒有任何內容表明按鈕單擊應觸發銷毀。
如果我有以下組件,則單擊按鈕時將在子組件中調用ngOnDestroy
。
<child *ngIf="!deleted"></child>
<button (click)="deleted = true">Trigger destroy in child</button>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.