[英]When clicking on like button it should show to particular data?
我有一個循環結構,其中包含帖子中的數據,如內容文本、照片、視頻,當單擊“喜歡”按鈕時我應該對數據做什么,它應該只選擇特定的索引數據。
由於我是 ionic 和 angular 的新手,我嘗試在按鈕單擊事件中使用索引 i 調用該數據,但它並不代表我返回任何東西。
.html file
<ion-button fill="clear" (click)="likebutton(i)">Like {{numberoflike[i]}}</ion-button>
.ts file
likebutton(){
this.numberoflike++;
}
我想選擇任何一個喜歡的數據代表我並只顯示給特定的喜歡按鈕。 如果可能,請讓我確認如何使用 *ngFor 並傳遞它的內部參數和值
你可以這樣做,
.ts 文件
export class MyComponent implements OnInit {
numberoflike:number[]=[];
itemsArray:number[]=[1,2,3,4,5,6,7];
likebutton(i){
this.numberoflike[i]++;//increment the count with given index
}
ngOnInit() {
this.itemsArray.forEach(()=>this.numberoflike.push(0));//initialize the likes array
}
}
.html 文件
<ion-card type="md" *ngFor="let item of itemsArray;let i=index;">
<ion-item (click)="likebutton(i)">
Like {{numberoflike[i]}}
</ion-item>
</ion-card>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.