angularjs - 无法使用 Angular9 传递数据
问题描述
我从后端获取了一组数据。数据应该是这样的
主页组件.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>
主页组件.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>
有什么简单的方法可以解决这个问题。请对此提出建议。
解决方案
我做了以下更改。现在我可以通过位置了。
<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>
推荐阅读
- html - Aria hack 为 html 标题标签分配不同的标题?
- javascript - 你可以在不扩展 Component 的 React 类上使用 componentDidMount() 吗?
- c# - 如何将泛型类型传递给扩展
- laravel - 从刀片模板中的 belongsToMany 关系中检索单个值
- java - 如何使用 jetty 嵌入式 8.1.16.v20140903 设置 HTTPS
- android - 推送通知不适用于 iPhone 到 Android 消息警报
- npm - npm 列表
给出错误的 UNMET PEER DEPENDENCY - python - 在坐标系中划定正方形
- latex - 如何从 postscript/gnuplot 转换为 pdf 保持乳胶文档的重音字母?
- c++ - 当标头位于 /usr/local/include 中时,我在哪里放置 cpp 文件?