2016-10-23 2 views
0

Ich verwende angular 1.4.x und Bluradmin Vorlage. Problem ist verbunden mit bootstrapswitch custom directiveRefresh bootstrapswitch nach Änderung in ngModel

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

Es lädt nur richtig, wenn während der Wiedergabe DOM und dann, nach Änderungen in ngModel, es aufzufrischen nicht. Wie kann ich es erreichen? BTW Ich kann es manuell wechseln, aber es ist kein Punkt.

Antwort

Verwandte Themen