Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed explicit setting of brackets for ngChange attribute #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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