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

Angular – How to prevent ngIf from destroying the component every time the condition changes

I have this code :

<ng-container *ngFor="let language of languages">
      <app-fields-to-translate
        *ngIf="language.ID === selectedLanguage.ID"
        [AttributeGroupsCollapses]="AttributeGroupsCollapses"
        [AttributeGroups]="AttributeGroups"
        [Attributes]="Attributes"
        [categoriesCollapsed]="categoriesCollapsed"
        [generalCollabsed]="generalCollabsed"
        [selectedLanguage]="selectedLanguage"
        (CategoriesCollapsedEmmiter)="categoriesCollapsed = $event"
        (CollapseGeneralEmmiter)="generalCollabsed = $event"
        (AddFieldToTranslation)="AddFieldToTranslation($event)"
        (AddAttrubuteToTranslation)="AddAttributeToTranslation($event)"
      >
      </app-fields-to-translate>
    </ng-container>

and every time the selctedLanguage changes the component of (field-to-translate) being destroyed
Can I prevent this process?
or is there another way to do this stuff?

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

>Solution :

Depending on what your business logic does exactly, you could use [hidden], ie

[hidden]="language.ID !== selectedLanguage.ID"

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