Closed jgentes closed 10 years ago
Might make sense to just wrap the toggle in a div with your custom class.
Thanks for the suggestion. This is a toggle-switch class, though:
<div class="switch-on">
<toggle-switch ng-model="adminStatus" style="margin-bottom: 5px;" class="danger" on-label="Yes" off-label="No"><toggle-switch>
</div>
So it doesn't work unless included in <toggle-switch>
.
However, I just noticed this:
ng-class="{'switch-off': !model, 'switch-on': model}"
So I may be able to manipulate the model to get the switch to the state I want. But it would be nice to be able to use ng-class rather than mess with the model beforehand.
Actually I was able to get around it with ng-init:
ng-init="adminStatus = isAdmin"
Now to figure out disabled..
Got it, I was able to address with disabled="!isAdmin"
You can also set the model in your controller. I tend to have init
functions that set default values.
angular.module('Admin', [])
.controller('AdminCtrl', function($scope, User) {
(function init() {
$scope.isAdmin = false;
})();
User.get().$promise.then(function(user) {
$scope.isAdmin = user.role === 'admin';
});
});
I haven't been able to get ng-class to work with toggle-switch:
I get errors like:
So it's clearly using ng-class to inject the { 'disabled': disabled } but I'm not sure how to add another ng-class expression in with it.
Any ideas?