I want to change the input value of discount when i click the button.
//parent.component.html
<button mat-raised-button (click)="addDiscount(5)" >5</button>
<div *ngFor="let items of itemSelected">
<item-box [quantity]="quantity" [discount]="discount">
</item-box>
</div>
//parent.component.ts
discount: number = 0;
addDiscount(disc: number){
this.discount = disc;
}
From your code it seems changing parent property will pass changed value to each child component
<button (click)="addDiscount(5)">Click Me to Send Data to Child</button>
<div *ngFor="let item of items" >
<br>
<app-child [discount]="discount" [childToMaster]=master
(childToParent)="childToParent($event)">
</app-child>
</div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.