0

How can I make a new array out of selected objects ?

.ts

  selectedObjects: object[];
  objectArray: object[];

.html

  <div *ngFor="let object of objectArray">
      <input [checked]="selectedObjects" type="checkbox" name="object.name" value="object.property2">{{object.name}}
    </div>

1 Answer 1

1

Bind your inputs to the change event :

<input type="checkbox" (change)="updateSelected(object.property2)" name="object.name" value="object.property2">{{object.name}}

In your TS :

updateSelected(value: string) {
  if (this.selectedObjects.includes(value)) {
    this.selectedObjects.splice(this.selectedObjects.indexOf(value));
  } else {
    this.selectedObjects.push(value);
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.