【问题标题】:Angular6 click event is not triggered in a loopAngular6点击事件不会在循环中触发
【发布时间】:2019-05-02 20:52:30
【问题描述】:

当我点击测试时,点击函数应该被调用。 但是什么都没有触发。

HTML 组件:

<div class="row m-0 justify-content-between" *ngFor="let i of 
k[currentk]?.details | keys">

    <div (click)="test(i.name)">{{i.name}}</div>

</div>

ts 组件:

import { Component, OnInit } from '@angular/core';

@Component({
 selector: 'app-test',
 templateUrl: './test.component.html',
 styleUrls: ['./test.component.scss']
})

export class TestComponent implements OnInit {

 constructor() {}

 ngOnInit() {}

 test(name){
   alert('Hello world');
 }
}

【问题讨论】:

标签: javascript angular html css


【解决方案1】:

你已经做对了。您不需要 div 标签中的 *ngFor 循环。只需删除它,您的代码就可以工作了。

【讨论】:

  • 糟糕,我应该添加动态名称。
  • 在任何图片上传网站的页面上发布您的结果截图并分享链接
  • 我需要看结果才能给出解决方案
猜你喜欢
  • 2018-04-18
  • 2020-12-27
  • 2013-05-19
  • 2015-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多