2017-05-06 61 views
0

这可能是一个简单的修复,但我想要做的只是在拖放结束时触发ng-change。如何仅在指令的拖动结束时触发ng-change?

之前,我从HTML这样做直:

<md-slider aria-label="{{ key }}" step="{{ value.step ? value.step : 1 }}" ng-model="filters.lastAppliedFilter.options[key].current" ng-change="filters.applyValue(filters.lastAppliedFilter.name, key, filters.lastAppliedFilter.options[key].current)" min="{{ value.min ? value.min : 1 }}" max="{{ value.max ? value.max : 250 }}"></md-slider> 

值从纳克重复的到来。

要检测dragend我创造了这个指令:

'use strict'; 

angular.module('image.directives').directive('testDragEnd', function() { 
    return { 
     restrict: 'A', 
     link: function(scope, element, attrs) { 
      element.on('$md.dragend', function() { 
       console.info('Drag Ended'); 
      }) 
     } 
    } 
}) 

我的问题是我怎么能触发NG-变化只在拖动结束?

谢谢。指令的内部

回答

0

我只是注射服务:

angular.module('image.directives').directive('testDragEnd', ['filters', function(filters) { 
    return { 
     restrict: 'A', 
     link: function(scope, element, attrs) { 
      element.on('$md.dragend', function() { 
       var key = attrs.ariaLabel; 
       filters.applyValue(filters.lastAppliedFilter.name, key, filters.lastAppliedFilter.options[key].current); 
      }) 
     } 
    } 
}]) 
相关问题