0

angular 1.4.x とBluradminテンプレートを使用しています。問題は、bootstrapswitch カスタム ディレクティブに関連しています

(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);
      }
    };
  }
})();

DOM のレンダリング中に一度だけ適切にロードされ、ngModel の変更後に更新されません。どうすれば達成できますか?ところで、手動で切り替えることはできますが、それはポイントではありません。

4

1 に答える 1

0

解決策は簡単でした。このディレクティブを使用しないでください。代わりに使用してください: https://github.com/JumpLink/angular-toggle-switch (特にis-disabled属性を確認してください。これは ngModel が変更されたときに機能します。代替ソリューションにはこの機能がありません: https://github. com/frapontillo/angular-bootstrap-switch/issues/96 )

于 2016-10-23T23:48:52.907 に答える