我不知道为什么 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
有什么想法吗?
答案 0 :(得分:4)
ngOnChanges
仅在@Input()
从上级组件更改时触发,而不是在子组件中更改。