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 ?
+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.
Most helpful comment
@irfanwv : No, sorry... I switched to React and Semantic UI a year ago !