事件传递 java_将事件传递/发送到父组件?
在Angular中,我可以創建一個發出動作的子組件:
@Component({
...
template: `
Click Me
`
})
export class ChildComponent {
@Output() onChildAction = new EventEmitter();
childAction() {
this.onChildAction.emit();
}
}
以及處理它的父組件 . 就像是:
@Component({
...
template: `
`
})
export class ParentComponent {
parentAction() {
console.log('Hello');
}
}
這樣可以正常工作,但有沒有辦法直接向父進行"passthrough"操作,而無需在調用 .emit() 的子進程中創建單擊處理程序?
就像是:
@Component({
...
template: `
Click Me
`
})
export class ChildComponent {
@Output() onChildAction = new EventEmitter();
}
和:
@Component({
...
template: `
`
})
export class ParentComponent {
parentAction() {
console.log('Hello');
}
}
事件立即發送到父級而不必經過子處理程序 . 當您只需單擊要讓父組件處理的子項中的事件時,這非常有用 .
總結
以上是生活随笔為你收集整理的事件传递 java_将事件传递/发送到父组件?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java中怎样验证重复文件_java –
- 下一篇: Java13的API_JAVA基础--J