Created
March 13, 2017 07:47
-
-
Save annibuliful/47e8bcb6d01b14fe578d27e02b7d633d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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