Skip to content

Commit

Permalink
Removed explicit setting of brackets for ngChange attribute. Code sho…
Browse files Browse the repository at this point in the history
…uld be backward compatibile - for settings without brackets, they should still be inserted automatically. This solves the issue xpepermint#10
  • Loading branch information
Tyrion85 committed Jan 17, 2017
1 parent bde4711 commit e2f100a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion angular-ui-switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ angular.module('uiSwitch', [])
var html = '';
html += '<span';
html += ' class="switch' + (attrs.class ? ' ' + attrs.class : '') + '"';
html += attrs.ngModel ? ' ng-click="' + attrs.disabled + ' ? ' + attrs.ngModel + ' : ' + attrs.ngModel + '=!' + attrs.ngModel + (attrs.ngChange ? '; ' + attrs.ngChange + '()"' : '"') : '';
html += attrs.ngModel ? ' ng-click="' + attrs.disabled + ' ? ' + attrs.ngModel + ' : ' + attrs.ngModel + '=!' + attrs.ngModel + (attrs.ngChange ? ('; ' + attrs.ngChange + (/^.*\(.*\).*$/.test(attrs.ngChange) ? '' : '()') + '"') : '"') : '';
html += ' ng-class="{ checked:' + attrs.ngModel + ', disabled:' + attrs.disabled + ' }"';
html += '>';
html += '<small></small>';
Expand Down
2 changes: 1 addition & 1 deletion angular-ui-switch.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ angular.module('app', ['uiSwitch'])

.controller('MyController', function($scope) {
$scope.enabled = true;
$scope.enabledWithArguments = true;
$scope.onOff = true;
$scope.yesNo = true;
$scope.disabled = true;
Expand All @@ -10,4 +11,8 @@ angular.module('app', ['uiSwitch'])
$scope.changeCallback = function() {
console.log('This is the state of my model ' + $scope.enabled);
};

$scope.changeCallbackWithArguments = function(arg) {
console.log('This is the state of my model ' + $scope.enabledWithArguments + '\nValue of passed argument is "' + arg.someArgument + '"' + "\n");
};
});
11 changes: 11 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
<p>
Enabled: {{ enabled }}
</p>

<!-- Example with callback function with arguments -->
<switch name="enabledWithArguments" ng-model="enabledWithArguments" ng-change="changeCallbackWithArguments({'someArgument': 'Awesome'})"></switch>
<p>
<button ng-click="enabledWithArguments=!enabledWithArguments">Toggle</button>
</p>
<p>
EnabledWithArguments: {{ enabledWithArguments }}
</p>


<!--Examples of using switch text on/off values. These values can be anything. First example shows basic on/off-->

<switch name="onOff" ng-model="onOff" on="on" off="off"></switch>
Expand Down

0 comments on commit e2f100a

Please sign in to comment.