Skip to content
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
4 changes: 2 additions & 2 deletions angular-ui-switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ 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 += ' ng-class="{ checked:' + attrs.ngModel + ', disabled:' + attrs.disabled + ' }"';
html += attrs.ngModel ? ' ng-click="' + attrs.ngDisabled + ' ? ' + attrs.ngModel + ' : ' + attrs.ngModel + '=!' + attrs.ngModel + (attrs.ngChange ? '; ' + attrs.ngChange + '()"' : '"') : '';
html += ' ng-class="{ checked:' + (attrs.invert === 'true' ? '!' : '') + attrs.ngModel + ', disabled:' + attrs.ngDisabled + ' }"';
html += '>';
html += '<small></small>';
html += '<input type="checkbox"';
Expand Down
2 changes: 1 addition & 1 deletion angular-ui-switch.min.css

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

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.

8 changes: 6 additions & 2 deletions example/app.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
angular.module('app', ['uiSwitch'])

.controller('MyController', function($scope) {
.controller('MyController', function($scope, $timeout) {
$scope.enabled = true;
$scope.onOff = true;
$scope.yesNo = true;
$scope.disabled = true;


$scope.dynamicDisabled = true;
$timeout(function() {
$scope.dynamicDisabled = false;
}, 1000);

$scope.changeCallback = function() {
console.log('This is the state of my model ' + $scope.enabled);
Expand Down
23 changes: 21 additions & 2 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en" ng-app="app">
<head>
<meta charset="utf-8">
Expand Down Expand Up @@ -43,9 +43,28 @@
<p>
<button ng-click="disabled=!disabled">Toggle</button>
</p>
<p>
Enabled: {{ disabled }}
</p>

<!--Example of using switch disabled states with dynamic update (enable after 1s). -->
<switch name="disabled" ng-model="disabled" disabled="dynamicDisabled"></switch>
<p>
Enabled: {{ disabled }}
<button ng-click="disabled=!disabled">Toggle</button>
</p>
<p>
Enabled: {{ disabled }}
</p>

<h4>Using invert - which shows the switch in the opposite arrangement</h4>
<!--Examples of using switch inverted. -->
<switch name="inverted" ng-model="inverted" invert="true"></switch>
<p>
<button ng-click="inverted=!inverted">Toggle</button>
</p>
<p>
Enabled: {{ inverted }}
</p>
</form>

</body>
Expand Down