我是Angular 2的新手,问题是如何触发从组件中点击HTML文件元素?
bool CheckString(string str)
{
return str.Length == 11 && str.StartsWith("09");
}
HTML文件(在课堂上点击活动=' rep')
rankingFilter() {
this.RepsloaderShow = true;
this.reps = [];
var data = {
from: this.fromFilter,
to: this.toFilter,
user_search: this.user_search
}
this.http.post(CONSTANTS.baseApiUrl + 'reports/rankings_individuals', data)
.map(res => res.json())
.subscribe((data) => {
this.reps = data;
this.RepsloaderShow = false;
// Trigger click here
});
}
答案 0 :(得分:5)
用于从主机元素发送
constructor(private elRef:ElementRef, private renderer:Renderer) {}
用于从模板内的元素调度
<some-elem #target></some-element>
@ViewChild('target') elRef:ElementRef;
然后发送活动:
...
this.renderer.invokeElementMethod(this.elRef.nativeElement,
'dispatchEvent',
[new MouseEvent('click', { bubbles: true, cancelable: true })]);