Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

$setViewValue() method also change the $modelValue #8131

Closed
kamalpatel125 opened this issue Jul 10, 2014 · 8 comments
Closed

$setViewValue() method also change the $modelValue #8131

kamalpatel125 opened this issue Jul 10, 2014 · 8 comments

Comments

@kamalpatel125
Copy link

Hi There,

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.

Thanks

Kamal Patel.

@Narretz
Copy link
Contributor

Narretz commented Jul 10, 2014

This is related to the discussion in #7976

@lrlopez
Copy link
Contributor

lrlopez commented 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
Copy link
Contributor

shahata commented 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
Copy link
Contributor

Narretz commented 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
Copy link
Contributor

lrlopez commented 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 $setViewValue directly.

@Narretz
Copy link
Contributor

Narretz commented 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)?

@Narretz Narretz added this to the Purgatory milestone Jul 17, 2014
@caitp
Copy link
Contributor

caitp commented Jul 17, 2014

@Narretz I believe @matsko is working on this, I'm happy to work with him on it though.

@btford btford removed the gh: issue label Aug 20, 2014
@Narretz
Copy link
Contributor

Narretz commented 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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants