You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
$setViewValue() method also change the $modelValue #8131
I have input text box control where i need display and model value different.
e.g. but instead of personid, i like to show "full name".
For that, I added directive to $setViewValue() for this input control element. But $setViewValue() method also change the $modelValue as well. So I don't see any benefit's of setting viewValue if it is changing the modelValue as well.
Line no : 16690 (AngularJS v1.2.10-build.2164+sha.8b395ff). Also, I checked the latest version and code looks the same.
If you need more information please let me know. Hope someone can help me on this issue.
Hmmm... Have you tried to write a formatter and a parser? The former allows translating the model into the view value while the later does the reverse (translating the view value into the model).
It's related to what @caitp said - the methods of ngModelController, especially $setViewValue do too much - if we expose them to the developer they should be consistent.
@Narretz, what I'm trying to say is that the proper Angular-way to do what @kamalpatel125 needs is using parsers and formatters, so he shouldn't need to call $setViewValue directly.
@lrlopez That is true, but the API should be predictable for the developers, and if we expose $setViewValue what it does should be reasonably easy to predict. btw @caitp are you working on the Great ngModelcontroller / Form handling refactoring (TM)?
On re-reading, I agree that this use case is possible with parsers / formatters, and that $setViewValue changes the modelValue by design, otherwise the two values would fall out of sync.
Activity
Narretz commentedon Jul 10, 2014
This is related to the discussion in #7976
lrlopez commentedon Jul 10, 2014
Hmmm... Have you tried to write a formatter and a parser? The former allows translating the model into the view value while the later does the reverse (translating the view value into the model).
shahata commentedon Jul 10, 2014
I don't think this is related to #7976 - this can be done easily with a formatter & parser as @lrlopez suggests
Narretz commentedon Jul 10, 2014
It's related to what @caitp said - the methods of ngModelController, especially $setViewValue do too much - if we expose them to the developer they should be consistent.
lrlopez commentedon Jul 11, 2014
@Narretz, what I'm trying to say is that the proper Angular-way to do what @kamalpatel125 needs is using parsers and formatters, so he shouldn't need to call
$setViewValuedirectly.Narretz commentedon Jul 17, 2014
@lrlopez That is true, but the API should be predictable for the developers, and if we expose $setViewValue what it does should be reasonably easy to predict. btw @caitp are you working on the Great ngModelcontroller / Form handling refactoring (TM)?
caitp commentedon Jul 17, 2014
@Narretz I believe @matsko is working on this, I'm happy to work with him on it though.
Narretz commentedon Oct 19, 2014
On re-reading, I agree that this use case is possible with parsers / formatters, and that $setViewValue changes the modelValue by design, otherwise the two values would fall out of sync.