Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

@Input() is undefined

I have 2 function in my angular component, first is for table and second returns list which is for child component. I call second one function firstly, but @Input is undefined. Also I try to call that function in child component , but there is also undefined. Below is two photo of my problem. OperationTypesFilter is for input. If I set value to operationTypesFilter
It works.

checkbox-filter.component.html

<ul class="pl-1">
    <li *ngFor="let filter of filters; index as i">
        <mat-checkbox color="primary" (change)="onItemSelect(filter,i)" [(ngModel)]="filter.checked">
            {{ filter.value | translate }}
        </mat-checkbox>
    </li>
</ul>

checkbox-filter.component.ts

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

this.list.forEach((item, id) => {
      this.filters.push({ id: item.id, value: item.name, checked: false })
    });

enter image description here
enter image description here

>Solution :

Issue: OperationTypesFilter is undefined because it is not set & is waiting to be set in subscribe,

solution:

  1. if it is required before loading the child component add a *ngIf="OperationTypesFilter" so it only loads when the value is available.

  2. if it will work with an empty array as well, set it to [] initially till the response comes back.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading