【问题标题】:Unable to pass data using Angular9无法使用 Angular 9 传递数据
【发布时间】:2020-11-01 04:57:02
【问题描述】:

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

用户界面 使用以下代码将以上数据绑定到表中

HomeComponent.html

<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

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.ng模型

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

 <td *ngIf='col
    ==="location"' ><input class="btn btn-default" type="submit" value="Download" (click) ="download(jre[col])"></td>

有什么简单的方法可以解决这个问题。 请对此提出建议。

【问题讨论】:

    标签: angularjs angular-ngmodel angular-ng-if angular-bootstrap


    【解决方案1】:

    我进行了以下更改。现在我可以传递位置了。

    <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>
    

    【讨论】:

      猜你喜欢
      • 2021-06-19
      • 2018-08-05
      • 1970-01-01
      • 1970-01-01
      • 2015-04-12
      • 1970-01-01
      • 1970-01-01
      • 2020-01-28
      • 2015-04-16
      相关资源
      最近更新 更多