0

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.

Michal_Szulc
  • 4,097
  • 6
  • 32
  • 59

1 Answers1

0

The solution was simple: do not use this directive. Instead use: https://github.com/JumpLink/angular-toggle-switch (especially check out it's is-disabled atribute, which will work when ngModel has changed. Alternative solution does not have this feature: https://github.com/frapontillo/angular-bootstrap-switch/issues/96)

Michal_Szulc
  • 4,097
  • 6
  • 32
  • 59