2015-09-11 56 views
2

我一直在使用這個GIT實現NOUI滑塊: https://github.com/vasyabigi/angular-nouislidernouislider事件

滑塊的順利實施。現在我想用AngularJS的方式來調用其滑動事件的函數。

我沒有找到任何文檔。

我在下面的鏈接中發現了這個滑塊事件,但是它的jQuery版本,我怎麼能以AngularJS方式使用這樣的滑塊事件。

http://refreshless.com/nouislider/events-callbacks/#section-binding

這裏是我的滑代碼:

<div slider ng-from="domainStrength.initial.start" ng-to="domainStrength.initial.end" start="{{ domainStrength.range.start}}" end="{{ domainStrength.range.end}}" step="{{ domainStrength.step}}" margin="{{ domainStrength.margin}}"></div> 

而且我希望這樣的事情:

<div slider ng-from="domainStrength.initial.start" ng-to="domainStrength.initial.end" start="{{ domainStrength.range.start}}" end="{{ domainStrength.range.end}}" step="{{ domainStrength.step}}" margin="{{ domainStrength.margin}}" onSlide="myCustomFun()"></div> 
+0

好的,我能夠通過將該使用事件:在模板

app.controller('SimpleController', function ($scope) { $scope.$watch('test.single', function (newVal, oldVal) { console.log('Value has changed', newVal, oldVal); }); $scope.$watchGroup(['test.from', 'test.to'], function (newVals, oldVals) { // NOTE: called whenever at least on of the watch values has changed console.log('From value', newVals[0], oldVals[0]); console.log('To value', newVals[1], oldVals[1]); }); }); 

用法 回調= 「變化」 變化='{{myCustom()}}在元件標籤 但頁面加載時,這個myCustom()調用11次,應該只調用使用幻燈片 –

回答

0

nouislider指令上幻燈片事件監聽你(可以改變它所監聽的事件,幻燈片是默認值)並更新您的模型值。如果你想檢測和處理模型改變,角度的方法是設置觀察者。例如:

<div ng-controller="SimpleCtrl"> 
    <div slider ng-model="test.single" start="1" end="10"></div> 
    <div slider ng-from="test.from" ng-to="test.to" start="0" end="100" step="5"></div> 
</div>