我如何检测模具中的道具变化,角度是这样的:
但我不知道模具中的情况如何。
import { Component, Input, OnInit } from '@angular/core';
@Component({
selector: 'my-name',
template: `
<h2>First name: {{name}} ({{_name}})</h2>
`,
})
export class ChildComponent implements OnInit {
private _name: string;
constructor() {}
get name(): string {
// transform value for display
return this._name.toUpperCase();
}
@Input()
set name(name: string) {
console.log('prev value: ', this._name);
console.log('got name: ', name);
this._name = name;
}
ngOnInit() {
console.log('on init');
console.log(this._name);
}
}
我需要检测属性变化