Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I recently wrote a custom directive for jqueryUiSlider.</p> <p>You can view it on GitHub ( <a href="https://github.com/jvandemo/CoconutJS/blob/master/src/jquery-ui/directives/ccnutJqueryUiSlider.js" rel="nofollow">https://github.com/jvandemo/CoconutJS/blob/master/src/jquery-ui/directives/ccnutJqueryUiSlider.js</a>) but I'll post it here for reference:</p> <pre><code>angular.module('ccnut.jquery-ui.directives') .directive('ccnutJqueryUiSlider', ['ccnut.config', 'logger', function (ccnutConfig, logger) { return { restrict: 'AC', require: 'ngModel', link: function (scope, iElement, iAttrs, ngModelController) { if (!window.$ || !window.$.fn || !window.$.fn.datepicker) { return logger.warn('ccnutJqueryUiSlider directive skipped: slider function from jQuery UI library not available'); } // Get options var options = angular.extend({}, scope.$eval(iAttrs.ccnutJqueryUiSlider)); // Initialize slider iElement.slider(options); // Update model on slide event iElement.on('slide', function (event, ui) { ngModelController.$setViewValue(ui.value); scope.$apply(); }); // Update slider when view needs to be updated ngModelController.$render = function () { var value = (ngModelController.$viewValue || 0); iElement.slider('value', value); }; } }; }]); </code></pre> <p>Here, the ngModelController is used to 'bind' the value of the slider to the model assigned to the directive using <code>ng-model="yourModelName"</code>.</p> <p>Usage is simple like this:</p> <pre><code>&lt;div ng-model="model" ccnut-jquery-ui-slider="{min:1, max:5}"&gt;&lt;/div&gt; </code></pre> <p>This will create a slider and store the value in the model specified by <code>ng-model</code>.</p> <p>When updating the model, the slider will also slide to the new value.</p> <p>You can read some extra documentation in the comments of the source code at <a href="https://github.com/jvandemo/CoconutJS/blob/master/src/jquery-ui/directives/ccnutJqueryUiSlider.js" rel="nofollow">https://github.com/jvandemo/CoconutJS/blob/master/src/jquery-ui/directives/ccnutJqueryUiSlider.js</a></p> <p>Hope that helps!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload