angularjs 使用ngstyle时“找不到不同的支持对象”

koaltpgm  于 11个月前  发布在  Angular
关注(0)|答案(2)|浏览(138)

我有一个进度条

<div class="progress-bar-line red" role="progressbar"  
    aria-valuenow="redrated" aria-valuemin="0" aria-valuemax="100"
    ngStyle="max-width:{{redrated}}%"
>
    <span class="title">{{ redrated }}%</span>
</div>

字符串
我已经使用ngStyle="max-width:{{redrated}}%"并尝试过:
1.在组件中创建了一个对象,并以ng样式调用它
1.即使ngStyle="{'max-width': '20px' }"也给出了同样的错误,请帮助我解决这个问题

k2arahey

k2arahey1#

<!DOCTYPE html>
    <html>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
    <body>
    <div ng-app="myApp" ng-controller="myCtrl">    
    <div class="progress-bar-line red" role="progressbar"  
                aria-valuenow="redrated" aria-valuemin="0" aria-valuemax="100"
                ng-style="{'max-width': '{{redrated}}%'}">
                <span class="title">{{ redrated }}%</span>
            </div>
    </div>
    
    <script>
    var app = angular.module('myApp', []);
    app.controller('myCtrl', function($scope) {
        $scope.redrated = 20;
    });
    </script>
    </body>
    </html>

字符串

hsgswve4

hsgswve42#

正确的语法是在键中定义像素,而不是在值中:

<div [ngStyle]="{'min-height.px':'700'}">
</div>

字符串
参见https://angular.io/api/common/NgStyle

相关问题