[英]Angular 7: ngOnChanges fires only once
我不知道為什么ngOnChanges
只觸發一次。 最初設置時。
import { Component, OnInit, Input, SimpleChanges, OnChanges } from '@angular/core';
@Component({
selector: 'app-fixed-decimals-input',
templateUrl: './fixed-decimals-input.component.html',
styleUrls: ['./fixed-decimals-input.component.scss'],
})
export class FixedDecimalsInputComponent implements OnInit, OnChanges {
@Input() value: number;
constructor() {}
ngOnInit() {}
ngOnChanges(changes: SimpleChanges) {
console.log(changes);
}
}
// html file
<input name="value" [(ngModel)]="value" />
更改值不會觸發ngOnChanges
任何想法?
ngOnChanges
僅在從父組件更改@Input()
時才觸發,而不是在子組件中更改時才觸發。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.