Material: select: with ng-change activates a change on each element when starting

Created on 20 Jan 2016  路  9Comments  路  Source: angular/material

Hi,

Every time md-select is initialized he activate the ng-change attached to for every element in the ng-model.

            <md-input-container>
                <label>Type de chauffage</label>
                <md-select ng-model="currentUser.bien.chauffage" ng-change="updateBien(currentUser.bien);" multiple="true">
                    <md-option ng-repeat="chauffage in chauffages" value="[[chauffage.value]]" >
                        [[chauffage.label]]
                    </md-option>
                </md-select>
            </md-input-container>

So with this code it launch 'updateBien()' for each elements in 'currentUser.bien.chauffage'.

Any idea ?

demo

Most helpful comment

@irfanwv : No, sorry... I switched to React and Semantic UI a year ago !

All 9 comments

+1
My current fix is to refuse using ng-change and implement model watcher.

This issue is closed as part of our 鈥楽urge Focus on Material 2' efforts.
For details, see our forum posting @ http://bit.ly/1UhZyWs.

@GautierT Have you found any solution for this?

@irfanwv : No, sorry... I switched to React and Semantic UI a year ago !

I used a flag(loading), a $timeout to change the value of the flag and the end of the method that loads the array.
And validate the flag at the beginning of the methods.

For anyone still having an issue, this is how I solved it:

<md-select
            aria-label="status"
            md-on-open="selectOpened = true"
            md-on-close="selectOpened = false"
            ng-change="updateStatus(selectOpened, row.entity)"
            ng-model="row.entity.status">
            <md-option-group>
                <md-option ng-value="true">Enabled</md-option>
                <md-option ng-value="false">Disabled</md-option>
            </md-option-group>
</md-select>
$scope.updateStatus  = function(selectOpened, subscription) {
            if ( selectOpened ) {
                   // change logic 
            }
};

I use the md-on-open and md-on-close to set a var and use that to determine if the change should be fired. It's not perfect but it works.

Not sure why my comment unassigned the issue 馃

@jgunderson-IAS thank you for posting your solution! Don't worry about the unassignment, GitHub does that now when someone is assigned to an issue but they are no longer on the team.

I was going to reopen this, but there is no CodePen reproduction in this issue. If you are still seeing this, please open a new issue with a CodePen reproduction and then we can investigate.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

buzybee83 picture buzybee83  路  3Comments

robertmesserle picture robertmesserle  路  3Comments

chriseyhorn picture chriseyhorn  路  3Comments

LeoLozes picture LeoLozes  路  3Comments

ddimitrop picture ddimitrop  路  3Comments