Angular2 get clicked element id

前端 未结 9 1920
深忆病人
深忆病人 2020-11-29 20:07

I have such click event

 
 
9条回答
  •  北海茫月
    2020-11-29 20:35

    do like this simply: (as said in comment here is with example with two methods)

    import {Component} from 'angular2/core';
    
    @Component({
        selector: 'my-app', 
        template: `
          
          
        `
    })
    export class AppComponent {
      checkEvent(event, id){
        console.log(event, id, event.srcElement.attributes.id);
      }
    }
    

    demo: http://plnkr.co/edit/5kJaj9D13srJxmod213r?p=preview

提交回复
热议问题