SajaWal NaWaz
SajaWal NaWaz

Reputation: 115

How do I use AngularJS with SVG tag ? I want to pass a parameter in SVG tag from angular

I want to take input from user through AngularJS and aapply it on a SVG circle tag. Is there anyone who could help me with this?

What I am doing is here:

<div class="app" ng-app>
  <div ng-controller="ctrlSizing">
    <label>Radius:
      <input ng-model="rad" type="number" placeholder="How about 300?">
    </label>
  </div>
</div>
<div style="height: 800; width: 500; position:absolute; left: 100px;top: 100px;">
  <svg width="500" height="500" visibility="visible">
    <circle id="circle1" cx="150" cy="150" r="getRad()" stroke="black" stroke-width="2" fill="grey" />
  </svg>
</div>

Upvotes: 0

Views: 802

Answers (1)

Vinay K
Vinay K

Reputation: 5572

Use ng-attr-r instead of r attribute on circle.

Markup

<div data-ng-controller="AppCtrl" id="ctrl">
    <input data-ng-model="rad"> {{rad}}
    <div style="height: 800; width: 500; position:absolute; left: 100px;top: 100px;">
            <svg width="500" height="500" visibility="visible" >
                <circle id="circle1" cx="150" cy="150" ng-attr-r="{{rad}}" stroke="black" stroke-width="2" fill="grey" />
            </svg>
    </div>
</div>

Upvotes: 2

Related Questions