AngularJS Slider指令(directive)擴充

來源:互聯網
上載者:User

繼上一篇基於jQuery UI Autocomplete的AngularJS 指令(directive)擴充,在這裡發布一個AngularJS的Slider擴充。如 果你還不瞭解AngularJS話的情參見AngularJs - Javascript MVC 架構,Angular-Bootstrap和Compiler以及Google-AngularJS 官方文檔.

jsfiddle示範:http://jsfiddle.net/whitewolf/vNfsm/20/embedded/:

html:

<center ng-app="app" ng-controller="test">        <green-slider  style="margin:20px;"></green-slider>    <green-slider ng-model="value" style="margin:20px;height:200px;" id="w1" class="22" ng-change="change();" range="min" min="10" max ="80" step ="1" orientation="vertical" ></green-slider>        <br/>    value:{{value}};    <input ng-model="value" maxlength="2" style="width:25px;"/>    </center>

js:

var prefixed = "green";     var appMoule = angular.module('app', []);     var slider = function() {    var linkFun = function($scope, element, attrs) {        $slider = jQuery(element);             var option = attrs;             var tryPrseInt = function(key, option) {            if (option[key]) {                option[key] = parseInt(option[key]);            }        };        tryPrseInt("min", option);        tryPrseInt("max", option);        tryPrseInt("step", option);        option = jQuery.extend({                 value: $scope[option.ngModel],                 change: function(event, ui) {                     if (attrs.ngModel && ui.value != $scope[attrs.ngModel]) {                         var express = attrs.ngModel + ' = ' + ui.value;                         $scope.$apply(express);                         if (attrs.ngChange) {                             $scope.$eval(attrs.ngChange);                         }                     }                 }             }, option);             $slider.slider(option);             //back             if (option.ngModel) {                 $scope.$watch(option.ngModel, function(val) {                     if (val != $slider.slider("value")) {                         $slider.slider("value", val);                     }                 });             }             console.log(attrs);         };         return {             restrict: 'E',             replace: true,             transclude: false,             template: '<center />',             link: linkFun         };     };     appMoule.directive(prefixed + "Slider", slider);     //test controller:測試代碼     var test = function($scope) {         $scope.value = 10;         $scope.change = function() {             console.log("change", this.value);         };     };     appMoule.controller("test", test);

同時有什麼問題請多多交流,功能進步

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.