Skip to content

Instantly share code, notes, and snippets.

@annibuliful
Created March 13, 2017 07:47
Show Gist options
  • Save annibuliful/47e8bcb6d01b14fe578d27e02b7d633d to your computer and use it in GitHub Desktop.
Save annibuliful/47e8bcb6d01b14fe578d27e02b7d633d to your computer and use it in GitHub Desktop.
//Product
export const Data = [
{name: 'name1'},
{name: 'name2'},
{name: 'name3'},
{name: 'name4'}
];
//template
<div *ngFor="let data of Data;let i = index;">
<p>{{data.name}}</p><p>{{i}}</p>
<button type="button" (click)="addProduct(i)">ssss</button> <== ตัวแปร i คือ index ของ Data ครับ
</div>
//function
addProduct(index){
this.UserProduct.push(this.Data[index]);
console.log(this.UserProduct);
alert(this.UserProduct);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment