我想将数据从
HTML传递到组件,所以我创建了这样的事件.
<div id="tutor-price" (click)="passCharge(r.value['charge'])"><span id="month">월 8회</span> <span id="price"> {{r.value['charge']}} </span></div>
在组件中,
passCharge(charge){ this.charge = charge; console.log(this.charge,"give me the number") }
如果我点击该活动,我看到一切正常.
但我希望自动触发此点击事件,因为我希望组件在组件完成加载后立即使用’this.charge’值.
给它一个ViewChild参考:
原文链接:https://www.f2er.com/angularjs/140407.html<div #myDiv id="tutor-price" (click)="passCharge(r.value['charge'])"><span id="month">월 8회</span> <span id="price"> {{r.value['charge']}} </span></div>
在您的组件中:
@ViewChild('myDiv') myDiv: ElementRef; triggerFalseClick() { let el: HTMLElement = this.myDiv.nativeElement as HTMLElement; el.click(); }