how to preserve input state of ngb-accordion on collapse

1k views Asked by At

Is it possible to save state (entered text) of the input when collapsing ngb-accordion?

Here is example: https://stackblitz.com/edit/angular-ukshlz-wz6st8?file=app/accordion-basic.html

If you enter some text into input and collapse / expand first panel then input loose it's contents.

1

There are 1 answers

3
Eliseo On BEST ANSWER

just use a variable and ngModel

myinput:any; //in your .ts

<input [(ngModel)]="myinput">  //your .html make use of the variable

Updated made by @tilias

if you use complex component structure, another possibility is setting destroyOnHide to false

<ngb-accordion [destroyOnHide]="false">

This will prevent destroying component, which holds your input and it's binding: see the docs

while I updated the answer, Tilias found the correct solution: remove my update