[英]Angular2: How to bind the mouse hover & out events for dynamically created the html string; Also, how to get those element?
這是場景:
在子組件中,我有條件地添加了一些html內容作為字符串。 我想為這些元素綁定懸停事件,並在鼠標懸停時進入父組件func。
ChildComponent{
...
someFunc(){
....
htmlDynamicContent = `<div (mouseover)="changeStyle($event)"
(mouseout)="changeStyle($event)”>Test</div>`
...
return htmlDynamicContent;
}
}
ParentComponent{
changeStyle (event){
//Change element styles
}
}
非常感謝您的幫助。 提前致謝。
將事件發射器添加到子組件:
@Output() onChangeStyle = new EventEmitter<any>();
懸停時發出:
<div (mouseover)="onChangeStyle.emit($event)"
(mouseout)="onChangeStyle.emit($event)”>Test</div>
然后綁定到父級中的EventEmitter:
<child (onChangeStyle)="changeStyle($event)"><child>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.