angular @Input
与@Output
双向绑定
@Input
允许父组件更新子组件中的数据;
@Output
允许子组件向父组件发送数据;
通过将同一个属性使用@Input
与@Output
一起绑定,使得数据在父组件和子组件之间同步更新。
angular的双向绑定遵循如下格式:
@Component({
selector:'app-test-component',
templateUrl:'./test.html',
styleUrls:['./test.css']
})
export class TestComponent{
@Input() attri:type;
@Output() attriChange = new EventEmitter<type>();
notifyAttri(){
this.attriChange.emit(this.attri);
}
}
<app-test-component [(attri)]="attri"></app-test-component>
Comments | NOTHING