I'm using angular 1.4.x and Bluradmin template. Problem is connected with bootstrapswitch custom directive
(function () {
'use strict';
angular.module('BlurAdmin.pages.form')
.directive('switch', switchDirective);
/** @ngInject */
function switchDirective($timeout) {
return {
restrict: 'EA',
replace: true,
scope: {
ngModel: '='
},
template: function(el, attrs) {
return '<div class="switch-container ' + (attrs.color || '') + '"><input type="checkbox" ng-model="ngModel"></div>';
},
link: function (scope, elem, attr) {
$timeout(function(){
var input = $(elem).find('input');
input.bootstrapSwitch({
size: 'small',
onColor: attr.color
});
input.on('switchChange.bootstrapSwitch', function(event, state) {
scope.ngModel = state;
scope.$apply();
});
}, 2000);
}
};
}
})();
It only loads properly once during rendering DOM and then, after changes in ngModel, it don't refresh. How can I achieve it? btw I can switch it manually but it is not a point.