0

此代码在所有主流浏览器中均可正常工作,但Edge仅在DOM检查器中显示有效值,但在页面仍旧保留旧值。为什么?为什么我的AngularJS指令在Edge中不起作用?

(function (angular, module) { 

    'use strict'; 

    module 
    .directive('psEffectsDurationSlider', EffectsDurationSlider); 

    EffectsDurationSlider.$inject = []; 

    function EffectsDurationSlider() { 
    return { 
     require: 'ngModel', 
     restrict: 'E', 
     link:  link 
    }; 

    function link(scope, element, attrs, ngModel) { 
     ngModel.$render = render; 

     activate(); 

     function initializeSlider() { 
     element.slider({ 
      min:   0.2, 
      max:   2, 
      step:  0.1, 
      animate:  true, 
      orientation: 'horizontal', 
      range:  'min', 
      slide:  onSliderChange 
     }); 
     } 

     function render() { 
     element.slider('value', ngModel.$viewValue); 
     } 

     function onSliderChange(event, ui) { 
     ngModel.$setViewValue(ui.value); 
     } 

     function onScopeDestroy() { 
     element.slider('destroy'); 
     } 

     function activate() { 
     initializeSlider(); 

     scope.$on('$destroy', onScopeDestroy); 
     } 
    } 
    } 

})(window.angular, window.angular.module('...')); 

从边缘截图与在DOM检查,并在页面有效值无效结果: enter image description here

回答

0

尝试包装模型更新中$timeout由于滑块事件是角上下文之外

function onSliderChange(event, ui) { 
    $timeout(function(){ 
     ngModel.$setViewValue(ui.value); 
    }); 
    } 

还需要注入$timeout

+0

已经尝试过。没有工作 – kovalevsky

相关问题