0

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.

3
  • Isn't Java-related, as far as I can tell, would you mind removing the java-tag? Commented Feb 9, 2020 at 19:46
  • Can you tel, what is listName? Please create a stackblitz to reproduce your error. Commented Feb 9, 2020 at 19:50
  • @AmitChigadani sorry mistake... I just edited Commented Feb 9, 2020 at 19:51

2 Answers 2

1

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 >
Sign up to request clarification or add additional context in comments.

Comments

0

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;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.