Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript到AngularJS指令_Javascript_Jquery_Angularjs - Fatal编程技术网

Javascript到AngularJS指令

Javascript到AngularJS指令,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,是否有人将justgage图表的纯javascript代码转换为angularjs指令。我在网上找到了一对,但并没有为我工作 <div id="g3"></div> <script type='text/javascript' src="https://code.jquery.com/jquery- 3.1.1.min.js"></script> <script src="../raphael-2.1.4.min.js"><

是否有人将justgage图表的纯javascript代码转换为angularjs指令。我在网上找到了一对,但并没有为我工作

<div id="g3"></div>
<script type='text/javascript' src="https://code.jquery.com/jquery-  3.1.1.min.js"></script> 
 <script src="../raphael-2.1.4.min.js"></script>
<script src="../justgage.js"></script>
 <script>

$(document).ready(function() {
   var g3;      

   var g3 = new JustGage({
     id: "g3",
     value: getRandomInt(0, 100),
     min: 0,
     max: 100,
     title: "Custom Colors",
     label: "",
     customSectors: [{
     color : "#00ff00",
     lo : 0,
     hi : 40
   },{
     color : "#00fff6",
     lo : 41,
     hi : 80
   },{
     color : "#ff0000",
     lo : 81,
     hi : 100
   }],

   counter: true
   });


     setInterval(function() {

       g3.refresh(getRandomInt(0, 100));
     }, 2500);

 });
 </script>

$(文档).ready(函数(){
var g3;
var g3=新调整器({
id:“g3”,
值:getRandomInt(0,100),
分:0,,
最高:100,
标题:“自定义颜色”,
标签:“,
海关部门:[{
颜色:“00ff00”,
劳:0,,
嗨:40
},{
颜色:“00fff6”,
劳:41,,
嗨:80
},{
颜色:“ff0000”,
劳:81,,
嗨:100
}],
柜台:对
});
setInterval(函数(){
g3.刷新(getRandomInt(01100));
}, 2500);
});
您可以尝试使用库。如果它对您不起作用,您可以创建自己的指令

请注意,此代码取自指令

查看

<just-gage id="d3" class="someClass" min=0 max=100 value=42 title="Test 1"></just-gage>
 angular.module('app', [])
  .directive('justGage', ['$timeout', function ($timeout) {
    return {
      restrict: 'EA',
      scope: {
        id: '@',
        class: '@',
        min: '=',
        max: '=',
        title: '@',
        label: '@',
        value: '@',
        options: '='
      },
      template: '<div id="{{id}}-justgage" class="{{class}}"></div>',
      link: function (scope, element, attrs) {
        $timeout(function () {
          var options = {
            id: scope.id + '-justgage',
            min: scope.min || 0,
            max: scope.max || 100,
            title: scope.title,
            label: scope.label || '',
            value: scope.value
          };

          if (scope.options) {
              for (var key in scope.options) {
                  options[key] = scope.options[key];
              }
          }

          var graph = new JustGage(options);

          scope.$watch('max', function (updatedMax) {
            if (updatedMax !== undefined) {
              graph.refresh(scope.value, updatedMax);
            }
          }, true);

          scope.$watch('value', function (updatedValue) {
            if (updatedValue !== undefined) {
              graph.refresh(updatedValue);
            }
          }, true);
        });
      }
    };
  }]);

指令

<just-gage id="d3" class="someClass" min=0 max=100 value=42 title="Test 1"></just-gage>
 angular.module('app', [])
  .directive('justGage', ['$timeout', function ($timeout) {
    return {
      restrict: 'EA',
      scope: {
        id: '@',
        class: '@',
        min: '=',
        max: '=',
        title: '@',
        label: '@',
        value: '@',
        options: '='
      },
      template: '<div id="{{id}}-justgage" class="{{class}}"></div>',
      link: function (scope, element, attrs) {
        $timeout(function () {
          var options = {
            id: scope.id + '-justgage',
            min: scope.min || 0,
            max: scope.max || 100,
            title: scope.title,
            label: scope.label || '',
            value: scope.value
          };

          if (scope.options) {
              for (var key in scope.options) {
                  options[key] = scope.options[key];
              }
          }

          var graph = new JustGage(options);

          scope.$watch('max', function (updatedMax) {
            if (updatedMax !== undefined) {
              graph.refresh(scope.value, updatedMax);
            }
          }, true);

          scope.$watch('value', function (updatedValue) {
            if (updatedValue !== undefined) {
              graph.refresh(updatedValue);
            }
          }, true);
        });
      }
    };
  }]);
angular.module('app',[])
.directive('justGage',['$timeout',function($timeout){
返回{
限制:“EA”,
范围:{
id:“@”,
类别:“@”,
最小:“=”,
最大值:'=',
标题:“@”,
标签:“@”,
值:'@',
选项:'='
},
模板:“”,
链接:函数(范围、元素、属性){
$timeout(函数(){
变量选项={
id:scope.id+'-justgage',
min:scope.min | | 0,
max:scope.max | | 100,
标题:scope.title,
标签:scope.label | |“”,
值:scope.value
};
if(范围选项){
for(scope.options中的var键){
选项[键]=范围。选项[键];
}
}
var图=新的JustGage(选项);
作用域:$watch('max',函数(updatemax){
if(updatemax!==未定义){
graph.refresh(scope.value,updatemax);
}
},对);
作用域:$watch('value',函数(updatedValue){
如果(updatedValue!==未定义){
图.刷新(updatedValue);
}
},对);
});
}
};
}]);