Angular2 how to bind map object from @input

2k views Asked by At

I have input in HTML like this:

<input class="form-control"
                   maxlength="255"
                   placeholder=""
                   type="text"
                   [(ngModel)]="data.translations[item.key]"
                   name="translations[{{item.key}}]"
                   >

I get from server DTO which contains map obejct. The DTO has name data and map name is translations.

Problem is, that for first time is value set to input correctly. But after button click, which sends value of input to server is input reset. I need the value to stay in input box. I think, that this binding should work. But it isn't.

Please help me, how I could correct this issue.

1

There are 1 answers

0
cherioss On

My colleague fix this with attributte: [ngModelOptions]="{standalone: true}" So now it looks like:

<input class="form-control" 
       maxlength="255" 
       placeholder="" 
       type="text" 
       [(ngModel)]="data.translations[item.key]" 
       [ngModelOptions]="{standalone: true}" 
       name="translations[{{item.key}}]" >