0

I'm trying to create the following:

Giving an array of objects, that every object represents a clickable line.

In the end it needs to look like the image below.

clock face

my code works mostly but i have 2 problems:

1: when looking in the log there are allot off errors.

Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Error: Invalid value for <rect> attribute transform="{{min.rotate}}"

2: the onClick isn't working (probably because of the errors)

My directive code:

    app.directive('clock24', ['$filter','$rootScope', function($filter,$rootScope) {
var linkFunction = function(scope, element, attributes) {
    scope.obj = attributes["clock24"];
    scope.hrs = [12,1,2,3,4,5,6,7,8,9,10,11];
    scope.mins = [];

    for(var i=0 ; i<60; i++){
      scope.mins.push(i)
    }


    scope.getHrs = function(){
        var res = [];
        var rotate = 0;
        var raze = 360/ scope.hrs.length;
        angular.forEach(scope.hrs, function(hr, key) {
            this.push({"key":key,"id":hr,"rotate":"rotate("+rotate+" 250 250)"});
            rotate+=raze;
        }, res);
        return res;
    };


     scope.getMins = function(){
        var res = [];
        var rotate = 0;
        var raze = 360/ scope.mins.length;
        angular.forEach(scope.mins, function(min, key) {
            this.push({"key":key,"id":min,"rotate":"rotate("+rotate+" 250 250)"});
            rotate+=raze;
        }, res);
        return res;
    };



};
return {
    restrict: 'A',
    scope: false,
    templateUrl: 'clockTemplate.html',
    link: linkFunction
  }
 }]);

My template code:

  <div class="timingClock">
 <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"            xml:space="preserve" style="shape-rendering:geometricPrecision; text- rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip-rule:evenodd" viewBox="0 0 500 500">
 <defs>
 <script type="text/ecmascript"><![CDATA[
  function changeRect(evt) {
      var svgobj=evt.target;
      // svgobj.style.opacity= 0.3;
      // svgobj.setAttribute ('x', 300);
      alert(svgobj.id);
  }
  ]]>
 </script>

 <radialGradient id="toning" cx="50%" cy="50%" r="50%" fx="50%" fy="50%">
      <stop offset="0%" style="stop-color: black; stop-opacity:0.3"/>
      <stop offset="100%" style="stop-color: #8c770d; stop-opacity:0.1"/>
 </radialGradient>
 </defs>

  <g id="UrTavla">
       <circle style="fill:none;stroke:#010101;stroke-width:1.6871;stroke-miterlimit:10;" cx="250" cy="250" r="245"></circle>

<g id="markeringar" class="Mrk">
  <rect  ng-repeat="hr in getHrs()"   x="245" y="5" width="20" height="20" id="{{hr.id}}"  onclick="changeRect(evt)" transform="{{hr.rotate}}"  ></rect>
  <rect  ng-repeat="min in getMins()" x="249" y="5" height="10" width="2"  id="{{min.id}}" onclick="changeRect(evt)" transform="{{min.rotate}}" ></rect>

</g>

plunker

Thanks a lot.

Avi

1 Answer 1

1

Something's wrong with the combined binding happening during the evaluation of your getHrs and getMins functions.

I was able to fix it by assigning their return values to scope variables:

scope.hrsRes = scope.getHrs();
scope.minsRes = scope.getMins();

And in the template:

ng-repeat="hr in hrsRes"
ng-repeat="min in minsRes"

Also, changeRect was undefined, and the clicks started to work once I moved it to script.js.

See it here: http://plnkr.co/edit/s1QU5XBLTAQJUHLlXXuS?p=preview

See this about out the rect attribute errors: D3 Integration with Angular: "Error: Invalid value for <rect> attribute x"

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much. That solved bowth of my problems

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.