首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用Angular9传递数据

无法使用Angular9传递数据
EN

Stack Overflow用户
提问于 2020-11-01 04:57:02
回答 1查看 13关注 0票数 0

我有一个从后端获取数据的数组。数据应该是这样的

UI

使用以下代码将上述数据绑定到表

HomeComponent.html

代码语言:javascript
复制
<table class="table table-hover" id =jres>     
          <thead>
            <th *ngFor="let col of columns">
              {{col}}
            </th>
          </thead>
          <tbody>
            <tr *ngFor="let jre of jreArray">
                <ng-container *ngFor="let col of index" >
                    <td *ngIf='col !=="location"'>{{jre[col]}}</td>
                    <td *ngIf='col ==="location"' ><input class="btn btn-default" type="submit" value="Download" (click) ="download()"></td>
                </ng-container>             
          </tbody>
      </table>

HomeComponent.ts

代码语言:javascript
复制
export class HomeComponent implements OnInit {

  constructor(private rs:RestService,private service:JreServiceService) { 
   
  } 
  columns= ["ID","JRE Name","Base Package","Download"];
  index=["id","jrename","basepackage","location"]
  jreArray: Array<IJre> = [];
  searchkey: any;
  path:any;

  ngOnInit(): void {
    this.service.getAllJre().subscribe(data=>{
      this.jreArray =  data;
      console.log(data)
    });
  }
 
  download(){
    alert(this.path)
    this.service.download(this.path).subscribe(data=>{
      this.jreArray = data;
    })
  }
}

当我点击下载按钮时,我需要将位置值传递给component.ts。

1.ngModel

2.使用以下代码将值直接传递给方法

代码语言:javascript
复制
 <td *ngIf='col
    ==="location"' ><input class="btn btn-default" type="submit" value="Download" (click) ="download(jre[col])"></td>

有没有简单的方法来解决这个问题。请对此提出建议。

EN

回答 1

Stack Overflow用户

发布于 2020-11-01 05:33:08

我已经在changes.now下面做了,我可以通过位置。

代码语言:javascript
复制
<tbody>
            <tr *ngFor="let jre of jreArray">
              <td >{{jre.id}}</td>
              <td >{{jre.jrename}}</td>
              <td >{{jre.basepackage}}</td>
              <td ><input class="btn btn-default" type="submit" value="Download" (click) ="download(jre.location)"></td>       
          </tbody>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64628794

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档