Sulu.MeanStack Sulu.MeanStack - 1 year ago 92
AngularJS Question

Set style for a div using angular Scope value

I have a horizontal div to show the percent of some activity. I have one outer div with

and one inner div. I have to fill the inner div with background color based on percentage value obtained from the controller, but my problem is that percentage value is in
variable percentage.

My code is below:

<div class="outerDiv">
<div class="innerDiv" style="'width':{{percentage}}"></div>

is my scope value. But the above code is not working fine so my need is that, I have to set style for div using scope value.plz help

Answer Source

You can use ng-style="{'width' : width}

In your controller:

$scope.width = '50%';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download