Angular2 How to trigger (click) event without clicking

后端 未结 3 534
耶瑟儿~
耶瑟儿~ 2020-12-25 12:12

I want to pass data from HTML to the component so I\'ve created an event like this:

3条回答
  •  醉梦人生
    2020-12-25 12:50

    You can trigger click event in ngOnInit() like this: `

    월 8회 {{r.value['charge']}}
    `

    In component.ts file

    import { Component, OnInit, AfterViewInit, ElementRef, ViewChild } from '@angular/core';
    @Component({
      //component decoraters
    })
    export class MyComponent implements OnInit, AfterViewInit {
      @ViewChild('divClick') divClick: ElementRef;
      ngOnInit() {
          // your other code
        setTimeout(() => {
        this.divClick.nativeElement.click();
        }, 200);
      }
    }
    

提交回复
热议问题