Angular2 get clicked element id

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

I have such click event

 
 
9条回答
  •  余生分开走
    2020-11-29 20:42

    If you want to have access to the id attribute of the button in angular 6 follow this code

    `@Component({
      selector: 'my-app',
      template: `
        
      `
    })
    export class AppComponent {
      clicked(event) {
        const target = event.target || event.srcElement || event.currentTarget;
        const idAttr = target.attributes.id;
        const value = idAttr.nodeValue;
      }
    }`
    

    your id in the value,

    the value of value is myId.

提交回复
热议问题