Sulu.MeanStack Sulu.MeanStack - 5 months ago 29
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

width=100%
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
$scope
variable percentage.

My code is below:

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


{{percentage}}
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

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

In your controller:

$scope.width = '50%';