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

koaltpgm  于 2024-01-05  发布在  Angular
关注(0)|答案(2)|浏览(240)

我有一个进度条

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

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

k2arahey

k2arahey1#

  1. <!DOCTYPE html>
  2. <html>
  3. <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
  4. <body>
  5. <div ng-app="myApp" ng-controller="myCtrl">
  6. <div class="progress-bar-line red" role="progressbar"
  7. aria-valuenow="redrated" aria-valuemin="0" aria-valuemax="100"
  8. ng-style="{'max-width': '{{redrated}}%'}">
  9. <span class="title">{{ redrated }}%</span>
  10. </div>
  11. </div>
  12. <script>
  13. var app = angular.module('myApp', []);
  14. app.controller('myCtrl', function($scope) {
  15. $scope.redrated = 20;
  16. });
  17. </script>
  18. </body>
  19. </html>

字符串

展开查看全部
hsgswve4

hsgswve42#

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

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

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

相关问题