1
import { Component, OnChange } from '@angular/core';
import { ChildComponent } from '../../reusable/user-offers/user-offers.component';
@Component({
...
directives: [ ChildComponent ]
})
export class ParentComponent implements OnChange {
@ViewChild(ChildComponent)
private child: ChildComponent;
ngOnChanges() {
detecting this.child.detectme variable...
}
}
子組件
import { Component, Input } from '@angular/core';
@Component({
...
})
export class ParentComponent {
@Input() detectme: string;
//in view something changes detectme value (not important here)
}
我如何檢測child.detectme改變並打印它的價值呢?
它是'ngOnChanges'而不是'ngOnChange' – Lekhnath
對不起,但那是手動重寫造成的。我有ngOnChanges。 – elzoy