cgarvis / angular-toggle-switch

AngularJS Toggle Switch
http://cgarvis.github.io/angular-toggle-switch
MIT License
160 stars 124 forks source link

Disabled based on scope value #70

Closed mariusbrn closed 9 years ago

mariusbrn commented 9 years ago

Why in your directive the attribute disabled is defined as a string? disabled="false" will disable the switch anyway. It's possible to achieve it with something like this:

 <toggle-switch disabled="{{ (isAdmin) ? '' : 'true' }}" ng-model="lock"></toggle-switch>

But your example with true leaves me thinking that the opposite is possible.

Maybe the local scope property should be = instead of @.

scope: {
    disabled: '=',
     ...
 },

This will give the possibility to disable the switch with a scope variable.

 <toggle-switch disabled="true" ng-model="lock"></toggle-switch>
 <toggle-switch disabled="false" ng-model="lock"></toggle-switch>
 <toggle-switch disabled="!isAdmin" ng-model="lock"></toggle-switch>