When using the ng-change directive and passing model information to a function, ng-change always passess: true; regardles if the switch is on/off. I would like to receive both states of true and false depending on on/off state.
I am using a custom switch directive based on switchery and angular-ui-switch
<switch
ng-model="app.layout.isNavbarFixed"
ng-change="uiSettingTypeChange('isNavbarFixed',
{{app.layout.isNavbarFixed}})"
class="green">
</switch>
and
$scope.uiSettingTypeChange = function(name, setting) {
console.log(name +' | ' + setting);
};
console.log always outputs:
isNavbarFixed | true
The value of the ng-change attribute is already an angular expression so there is no need for the
{{}}
. What I guess is happening, is that angular sees the{{}}
and thus evaluates it. So, at that point the ng-change effective looks like this:Then, when the change event is firing, it's just passing that true in every time. What you want should look more like this: