Giter Site home page Giter Site logo

Add support for more events about ui-slider HOT 4 CLOSED

ahc2483 avatar ahc2483 commented on September 15, 2024
Add support for more events

from ui-slider.

Comments (4)

enodyt avatar enodyt commented on September 15, 2024

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.

johnparn avatar johnparn commented on September 15, 2024

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.

kencaron avatar kencaron commented on September 15, 2024

@enodyt Thanks, that explanation definitely helped & worked for me in lieu of documentation.

from ui-slider.

arambert avatar arambert commented on September 15, 2024

maybe this could be useful : #104

from ui-slider.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.