如何单击按钮将所需值发送到Angular 4控制器?

时间:2018-04-04 04:37:05

标签: angular typescript

我有这个HTML代码:

 <div class="btn-group" role="group" aria-label="Basic example" *ngFor="let techlist of technology">
    <button type="button" class="btn btn-secondary" (click)="resList()">{{techlist.TechnologyRouteTitle}}</button>
  </div>

该技术有一个视图模型:

public ComponentTypeId: number;
public ComponentTypeTitle: string;
public TechnologyRouteId: number;

现在有4个元素。他们有一个独特的TechnologyRouteKey。通过点击其中一个,我需要加载一系列技术。我有这个功能:

  resList(): void {
    this.TestService.getResearchList(this.filterResearchList)
      .then(response => {
        this.technology = response.Object;
      });
  }

this.filterResearchList有这样的视图模型:

public CompanyId: number;
public TechnologyRouteKey: string;

公司ID始终相同,但需要根据您按下的按钮更改TechnologyRouteKey,我该怎么做?已经花了一个小时,它不起作用。哪种方式看?

1 个答案:

答案 0 :(得分:0)

如果你想传递值,那么你应该将click函数传递给像这样的参数

(click)="resList(argument)" //in template html file 

这意味着如果我是正确的,它应该是这样的(检查点击功能我通过了路由ID)

<div class="btn-group" role="group" 
     aria-label="Basic example" *ngFor="let techlist of technology">
    <button type="button" class="btn btn-secondary" 
      (click)="resList(techlist.TechnologyRouteId)">
               {{techlist.TechnologyRouteTitle}}</button>
  </div>

和ts文件

 resList(argument): void {
 }