javascript - How to include angular JS expressions inside an SVG circle -


i have following html code create concentric circles.

<div id="delightmeter">    {{delightscore}}     <svg width='500px' height='300px' version='1.1' xmlns='http://www.w3.org/2000/svg'>               <g class=''>                   <circle class='' cx='200' cy='60' r='20'></circle>                 <circle class="" cx='200' cy='60' r='17' ></circle>           </g>      </svg>  </div> 

i have js file in operations using angular js , have value in $scope variable. there way access variable other file , show inside svg circle

update:

'use strict';

angular.module('delightmeterapp', [  ])     .directive('delightmeter', function () {         function link($scope, $element, $attrs) {               document.getelementbyid("arc1").setattribute("d", describearc(200, 200, 100, -90, -56));             document.getelementbyid("arc2").setattribute("d", describearc(200, 200, 100, -54, -20));             document.getelementbyid("arc3").setattribute("d", describearc(200, 200, 100, -18, 16));             document.getelementbyid("arc4").setattribute("d", describearc(200, 200, 100, 18, 52));             document.getelementbyid("arc5").setattribute("d", describearc(200, 200, 100, 54, 90));                function polartocartesian(centerx, centery, radius, angleindegrees) {                 var angleinradians = (angleindegrees - 90) * math.pi / 180.0;                  return {                     x: centerx + (radius * math.cos(angleinradians)),                     y: centery + (radius * math.sin(angleinradians))                 };             }             /* function draw single arcs recieving (start co-ordinatex,start co-ordinatey,radius,start angle, end angle) */             function describearc(x, y, radius, startangle, endangle) {                  var start = polartocartesian(x, y, radius, endangle);                 var end = polartocartesian(x, y, radius, startangle);                 var arcsweep = endangle - startangle <= 180 ? "0" : "1";                 var d = [                     "m", start.x, start.y,                     "a", radius, radius, 0, arcsweep, 0, end.x, end.y                 ].join(" ");                 return d;             }               function scorerotateneedle(delightscore) {                 $('.needleset').css({                     "transform": "rotate(" + delightscore + "deg)",                     "transform-origin": "50% 95%"                 });             }              $scope.$watch('score', function () {                 scorerotateneedle($scope.score);             });          }          return {             restrict: 'e',             templateurl: 'svgmeter.html',             scope: {                 score: '=ngmodel'             },             link: link         };     })     .controller('delightmetercontroller', function ($scope) { $scope.delightscore = 0;        }) 

i need access delightscore variable inside custom directive in html template.

i have updated plunker delight score shows text in svg.

http://plnkr.co/edit/twenjm0h7f6npc2mm9l2?p=preview

since have value of delightscore in directives scope called "score" can use in svg template {{score}}

    <svg width='500px' height='300px' version='1.1' xmlns='http://www.w3.org/2000/svg'>      <g>         <text x='100' y='220' fill='black'>0</text>         **<text x='195' y='220' fill='black'>{{score}}</text>**         <text x='300' y='220' fill='black'>100</text>         <path class='arc' id='arc1' d='' />         <path class='arc' id='arc2' d='' />         <path class='arc' id='arc3' d='' />         <path class='arc' id='arc4' d='' />         <path class='arc' id='arc5' d='' />         <g class='needleset'>             <circle class='needle-center' cx='200' cy='200' r='5'></circle>             <path class='needle' d='m 195 198 l 200 100 l 205 202'></path>             <circle class='needle-center' cx='200' cy='200' r='5'></circle>         </g>     </g>  </svg> 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -