Comments (4)
slider-ui depends and provides (an empty) uiSliderConfig
service.
You can configure your sliders by providing an uiSliderConfig
service with your app:
app.factory('uiSliderConfig', function ($log) {
return {
start: function (ev, ui) { $log.info(ev, ui); },
stop: function (ev, ui) { $log.info(ev, ui); }
};
});
Alternatively you can setup the slider by setting the options on the ui-slider attribute in your template:
<div ui-slider="slider.options" ng-model="slider.val"></div>
and in your controller:
app.controller('AppCtrl', function ($scope, $log) {
$scope.slider = {
val: 0,
options: {
change: function (ev, ui) { $log.info($scope.slider.val); }
}
}
});
If we wanted to apply the handler functions directly to the directives scope
we would have to enhance the setup implementation a little bit:
var options = angular.extend(/* ... */);
angular.forEach(options, function (value, key) {
if (angular.isFunction(value)) {
options[key] = function (ev, ui) {
return value.apply(this, [ev, ui, scope]);
}
}
});
Not sure about that – just started playing with angular, maybe there's a better way passing the scope to event handlers – however we would then be able to do something like this:
app
.value('uiSliderConfig', {
change: function (ev, ui, scope) {
console.log(scope.calc.something());
}
}
.controller('appCtrl', function ($scope) {
$scope.calc = {
something: function () {
console.log('beep');
}
}
});
from ui-slider.
As @enodyt wrote you can register events, for example start and stop events, by passing the event callbacks using the ui-slider config. Here's a plunker demonstrating that:
http://embed.plnkr.co/FtIl5zVSeII6VRTKOuF7/
In this example the slider is setup with the following markup:
<div ui-slider="{start: sliderStart, stop: sliderStop}" min="0" max="20" step="2" ng-model="sliderValue"></div>
sliderStart
and sliderStop
are both functions available declared in the controller. For example:
$scope.sliderStart = function(event, ui) {
console.log('Event started at ', new Date());
console.log(event);
}
$scope.sliderStop = function(event, ui) {
console.log('Event stopped at ', new Date());
console.log(event);
}
// John
from ui-slider.
@enodyt Thanks, that explanation definitely helped & worked for me in lieu of documentation.
from ui-slider.
maybe this could be useful : #104
from ui-slider.
Related Issues (20)
- Updated demo page HOT 2
- Please publish 0.1.3 on NPM HOT 8
- add touchdrag support for handles - Feature HOT 3
- Version problem HOT 2
- Range-Slider locks on max value if ng-model-options: debounce is used
- Can we add this package to the npm registry? HOT 1
- Max/Min dynamically range changes.
- Slide event cancellation doesn't keep previous slider values HOT 2
- Update angular version
- Ticks does not get updated when the Max value is changed dynamically.
- The slider is not working on IE-8 and IE-9 browser?
- Upgrade to jQuery UI 1.11 HOT 3
- elm.slider is not a function HOT 4
- Setting min and max values dynamically. HOT 1
- model to define steps array with numbers to allow slider to snap into defined numbers only HOT 1
- uh - zero size HOT 3
- If you have multiple ui-slider's with different min/max values, but the same option object, the mix/max become the same for all the sliders. HOT 2
- Dual Knobs would be great! HOT 1
- Feature, use dates?
- Changing min/max values after slider creation? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ui-slider.