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

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

Closed

Description

@kamalpatel125

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.

Activity

  1. Narretz commented on Jul 10, 2014

    @Narretz
    Contributor

    This is related to the discussion in #7976

  2. lrlopez commented on Jul 10, 2014

    @lrlopez
    Contributor

    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).

  3. shahata commented on Jul 10, 2014

    @shahata
    Contributor

    I don't think this is related to #7976 - this can be done easily with a formatter & parser as @lrlopez suggests

  4. Narretz commented on Jul 10, 2014

    @Narretz
    Contributor

    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.

  5. lrlopez commented on Jul 11, 2014

    @lrlopez
    Contributor

    @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.

  6. Narretz commented on Jul 17, 2014

    @Narretz
    Contributor

    @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)?

  7. added this to the Purgatory milestone on Jul 17, 2014
  8. caitp commented on Jul 17, 2014

    @caitp
    Contributor

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

  9. Narretz commented on Oct 19, 2014

    @Narretz
    Contributor

    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions