ng-style not taking scope value

时间:2017-06-12 16:49:00

标签: angularjs

I have a couple views and I'm looking to adjust the container width based on the view I'm in.

<!-- our main container area for the views -->
<div class="container" ng-style="{ 'width': '95%' }">
    <div class="row" style="height: 100%;">
        <!-- below is where the partial pages will replace -->
        <div style="height: 100%;" ng-view></div>
    </div>
</div>

When I hardcode the ng-style width property it works. Above I hardcode it to 95%. However, when I set it to a scope variable and set that variable inside the view's controller it doesn't work.

<div class="container" ng-style="{ 'width': containerWidth }">

Inside one of the view controllers:

$scope.containerWidth = '95';

1 个答案:

答案 0 :(得分:1)

It should be,

<div class="container" ng-style="{ 'width': containerWidth + 'px' }">

DEMO