Reputation: 75
I wouldike to send data from another component but it does not work when I am doing this :
source.html:
<app-heat [value]="selectedValue" [list]="values"> </app-heat>
source.ts :
selectedValue = {
Name: '',
Matricule: '',
}
values = [{
Name: "Container A",
Matricule: "ABC",
},
{
Name: "Container B",
Matricule: "BCD",
},
destination data for another component :
destination.html
<input type="checkbox" *ngFor="let v of list;let i = index" [list]="i">{{list}}<br>
destination.ts
@Input() value: string;
@Input() list: string;
I need to get data from values (name : Container A and Container B) on my input checkbox.
Upvotes: 0
Views: 101
Reputation: 1547
Try this code, and for test set your selectedValue:
selectedValue = {
Name: 'Container A',
Matricule: 'ABC',
};
destination.ts:
@Input() value: any;
@Input() list: any[];
destination.html:
<ng-container *ngFor="let v of list;let i = index">
<label [for]="i">{{v.Name}}</label>
<input type="checkbox" [id]="i" [checked]="v.Name===value.Name && v.Matricule===value.Matricule" >
</ng-container >
Upvotes: 1
Reputation: 638
You can try this.
source.html
<app-heat [value]="selectedValue" [list]="values"></app-heat>
source.ts
selectedValue = {
Name: 'Container B',
Matricule: 'BCD',
};
values = [
{
Name: "Container A",
Matricule: "ABC",
},
{
Name: "Container B",
Matricule: "BCD",
}
];
destination.html
<div *ngFor="let v of list">
<input type="checkbox" value="{{ v.Name }}">
<label>{{v.Name}}</label>
</div>
You can show all selected checkboxes by the selected value
<div *ngFor="let v of list">
<input type="checkbox" value="{{ v.Name }}" [checked]="v.Name==value.Name">
<label>{{v.Name}}</label>
</div>
destination.ts
@Input() value: any;
@Input() list: any;
Upvotes: 0