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.

Changing ng-options datasource is firing the ng-change automatically #16586

Description

@amiteshhh

I'm submitting a ...

  • bug report
  • feature request
  • other

Current behavior:
Changing ng-options underlying datasource is triggering the ng-change handler when underlying ng-model was changed programmatically previously.

Expected / new behavior:
It should not trigger ng-change handler.

Minimal reproduction of the problem with instructions:

dd1 and dd2 are two independent dropdowns having different ng-options data source containing array of objects.
Step 1: Set ng-model for dd2 programmatically by clicking the button. This is not firing the ng-change handler of dd2 which is correct.

Step 2: Now change the dd1. Inside dd1 change handler assign new array data source to dd2 ng-options. This is automatically triggering the ng-change of dd2.

Demo link: https://plnkr.co/edit/mI44WPHmlPf5B6Sdpbxr?p=preview

AngularJS version: 1.6.9

Issue still exists in the most recent stable version 1.7.0 and in the snapshot AngularJS 1.7.1-build.26050+sha.0b1adbb

Browser: [all | Chrome 66 | Edge 40 | IE 11 ]

Activity

  1. changed the title [-]Changing ng-options is firing the ng-change automatically[/-] [+]Changing ng-options datasource is firing the ng-change automatically[/+] on Jun 1, 2018
  2. gkalpak commented on Jun 1, 2018

    @gkalpak
    Member

    It seems that whenever one of the values watched by ngOptions is changed, we might end up calling $setViewValue(). This seems incorrect if the changes can be a result of a change on the model side (as is the case in the above example).

    @Narretz probably knows more.

  3. added this to the 1.7.x milestone on Jun 1, 2018
  4. Narretz commented on Jun 4, 2018

    @Narretz
    Contributor

    The behavior is intentional: #7736 I can see how this can be confusing / unwanted, but it's an either-or situation and we've "fixed" this behavior, so we cannot go back. Why exactly is it a problem for your app that the model us updated @amiteshhh ?

  5. amiteshhh commented on Jun 4, 2018

    @amiteshhh
    Author

    @Narretz In our app we have a drop-down to select country. Based on country selection we display different information for that country. The information contains data for month drop-down(driven by country). By default we are initializing default month to show the default view. Additionally on change of month we fetch data for selected month.
    Now user changes country to see information of other country and again we are fetching new set of data including months but at this moment ng-change handler of months automatically triggered by Angular(and this is the whole problem).
    By maintaining the same reference of months array its not triggering the ng-change handler but this seems less obvious/awkward solution.

  6. AndrewMacKay-base commented on Jan 23, 2019

    @AndrewMacKay-base

    Following as this is also an issue for our team at present

  7. aaronpikkarainen commented on Jul 31, 2019

    @aaronpikkarainen

    It's my understanding that the purpose of ng-change is to know when the user changes the value. It's not supposed to fire simply when the model is changed programmatically.

    I agree that the ng-model value should be updated in this particular case (as fixed in #7736), but I don't think the ng-change should be fired.

    If this is an accurate understanding of the purpose of ng-change. could we get a fix for this?

  8. Narretz commented on Aug 6, 2019

    @Narretz
    Contributor

    @aaronpikkarainen AngularJS is in LTS mode, so we are only going to fix security bugs.

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