0

I have a problem with show checked data in Array in Angular app. When I click on the checkbox I get a true value, but data not show. Data has null value.

StackBlitz: https://stackblitz.com/edit/angular-ivy-kt2uag?file=src%2Fapp%2Fapp.component.ts

code:

component.ts

I use this function:

fetchSelectedItems() {
    this.selectedItemsList = this.checkboxesDataList.filter((value, index) => {
      console.log(value.selected);
      return value.selected === true;
    });
  }

  fetchCheckedIDs() {
    this.checkedIDs = [];
    this.checkboxesDataList.forEach((value, index) => {
      if ((value.selected)) {
        this.checkedIDs.push(value.code);
      }
    });
  }
2
  • What is the problem or error you are facing ? Commented Apr 16, 2021 at 13:10
  • this.checkedIDs.push(value.code); not show data from value.code what I need Commented Apr 16, 2021 at 13:12

1 Answer 1

2

You are calling fetchCheckedIDs() just on ngOnInit(){}. Call the method in your fetchSelectedItems() too:

  fetchSelectedItems() {
    this.fetchCheckedIDs(); //call here
    this.selectedItemsList = this.checkboxesDataList.filter((value, index) => {
      console.log(value.selected);
      return value.selected === true;
    });
  }

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.