Iv有一个有角度的应用程序,它从spring-boot rest api(简单播放器对象的集合-id,name,position,value ...的集合)中读取json资源...。我有一个按钮,其中每个简单显示的对象都位于UI上,而我只是想在用户单击component.html上的“购买”按钮时将每个对象存储在数组中。...我需要使用我的component.ts文件,而我是TypeScript的新手,不确定如何链接html方法调用.ts逻辑页面...
任何帮助,不胜感激的家伙。...这只是我基本的幻想足球类型应用程序的第二阶段,其中的列表(如果我在Java中,则为arraylist)将代表用户选择购买的玩家/他们的自定义团队... ..
COMPONENT.HTML:
<ul *ngIf="Ballers">
<li *ngFor="let player of Ballers">
<p class="name">{{player.name}}</p>
<p class="position">{{player.position}}</p>
<p class="value">£{{player.value}} m</p>
<button class="buyButton" on-click="buyThisPlayer()">Add to Squad</button>
</li>
</ul>
</div>
COMPONENT.TS:
@Component({
selector: 'app-player-list',templateUrl: './playerList.component.html',styleUrls: ['./playerList.component.scss']
})
export class PlayerListComponent implements OnInit {
Ballers: Object;
// let selectedKickers=[] ; //to declare my empty array???
constructor(private httpService: HttpService) { }
ngOnInit() {
this.httpService.getPlayers().subscribe(data => {
this.Ballers = data;
console.log(this.Ballers);
})
}
buyThisPlayer(){
selectedKickers.push(this); // this seems the only way to pinpoint my object to add???
}
}