Reputation: 2823
I have a primeng form that creates/updates the user model on form submission. I want to update another model at the same time. That is, I want to get the username in the form and create another model object with that value.
<input type="text" class="form-control" name="login" #loginInput="ngModel"
[(ngModel)]="user.login" required minlength="1" maxlength="50" pattern="^[_.@A-Za-z0-9-]*$">
With the [(ngModel)]="user.login"
I want to save both the "user.login"
and modelX.paramX
with the same value. Is it possible to fill both models in the form?
Or do I have to get the value and do it separately in the component.ts? If so how do I do it?
Upvotes: 0
Views: 1827
Reputation: 24
The only way that I have found you can achieve this is by using the change event of the input it will be like this:
<input id="twomodel" name="twomodel" [(ngModel)]="X" (change)="Y= X" type="text" #twomodel="ngModel" />
see the change event I just made it to assign the bind value to the other value
here is the link that i got this solution from (It uses the angularjs): How to bind 2 models to one input field in Angular?
Hope that helps
Upvotes: 1