gpt4 book ai didi

html - 如何触发点击组件中的 HTML 文件元素? ( Angular 2)

转载 作者:行者123 更新时间:2023-11-28 04:47:55 25 4
gpt4 key购买 nike

我是 Angular 2 的新手,问题是如何从组件触发对 HTML 文件元素的点击?

  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

});
}

HTML 文件(class='rep' 上的点击事件)

    <ul class="carousel-indicators section-nav">
<li class=" icon_0 icon active rep" data-target="#slideable" data-slide-to="0">
<span class='shh'>Reps</span>
<p style="display: none;">Reps</p>
</li>
<li class="icon_0 icon team" data-target="#slideable" data-slide-to="1">
<span class='shh'>Teams</span>
<p style="display: none;">Teams</p>
</li>
<li class="icon_0 icon award" data-target="#slideable" data-slide-to="2">
<span class='shh'>Class Ranks</span>
<p style="display: none;">Class Ranks</p>
</li>
</ul>

最佳答案

用于从宿主元素调度

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 })]);

关于html - 如何触发点击组件中的 HTML 文件元素? ( Angular 2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40103772/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com