呼叫中心信息公示平台

angular.radialIndicator.js 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* Angular hook for radialIndicator */
  2. ;
  3. (function (angular) {
  4. angular.module('radialIndicator', []).directive('radialIndicator', ['radialIndicatorInstance',
  5. function (radialIndicatorInstance) {
  6. return {
  7. restrict: 'A',
  8. link: function (scope, element, attrs) {
  9. var element = element,
  10. id = attrs.radialIndicatorId,
  11. options = scope.$eval(attrs.radialIndicator),
  12. model = attrs.radialIndicatorModel;
  13. var indInstance = radialIndicator(element, options);
  14. //store indicator instance on radialIndicatorConfig so can get through dependency injection
  15. if (id) radialIndicatorInstance[id] = indInstance;
  16. //watch for modal change
  17. scope.$watch(model, function (newValue) {
  18. indInstance.value(newValue);
  19. });
  20. //delete the idnicator instance when scope dies
  21. scope.$on('$destroy', function () {
  22. if (id) delete radialIndicatorInstance[id];
  23. });
  24. }
  25. }
  26. }])
  27. //a factory to store radial indicators instances which can be injected to controllers or directive to get any indicators instance
  28. .factory('radialIndicatorInstance', function () {
  29. if (!window.radialIndicator) throw "Please include radialIndicator.js";
  30. var radialIndicatorInstance = {};
  31. return radialIndicatorInstance;
  32. });
  33. }(angular));