export class Test {
a1: number;
name: string;
}
@Component({
selector: '[t1-info]',
templateUrl: './t1component.html',
})
export class T1InfoComponent implements OnInit {
@Input() test: Test;
constructor() { }
ngOnInit() {
}
}
<div t1-info [test]="test"></div>
<button (click)='test.a1 = test.a1-1'>test</button>
或
http.get(....).subscribe(res=>{
test.a1=1;
})
如何观看test.a1更改? 与angular1 $ Watch
类似答案 0 :(得分:1)
您可以使用@output()
触发该组件中所做的任何更改,并调用任何函数来侦听更改
export class Test {
a1: number;
name: string;
}
@Component({
selector: '[t1-info]',
templateUrl: './t1component.html',
})
export class T1InfoComponent implements OnInit {
@Input() test: Test;
@Output() changeEvent: new EventEmitter();
constructor() { }
ngOnInit() {
}
changeEvent(){
console.log(this.test, "Changes")
}
}
<div t1-info [test]="test"></div>
<button (click)='test.a1 = test.a1-1'>test</button>