在angularjs ui网格中,我有如下所示的单元格模板:
cellTemplate : "<div class="progress"> <div class="progress-bar progress-bar-info" ></div> </div>"
现在我需要动态更改cellTemplate的颜色类,即progress-bar-info
。基于列值(完整,不完整,正在进行或失败)我需要在cellTemplate中有progress-bar-success, progress-bar-info, progress-bar-warning, progress-bar-danger
。我们怎样才能实现它?
我尝试了以下模板,但它给出了错误:
cellTemplate: " <div class=\"progress margin-top-10\"> <div class=\"progress-bar\" ng-class=\"{progress-bar-success:{{row.entity.status}}==='complete', progress-bar-warning:{{row.entity.status}}==='incomplete', progress-bar-danger:{{row.entity.status}}==='fail'}\" ng-style=\"{width:'{{row.entity.val}}%'}\"></div> </div>",
错误如下:
angular.js:13920 Error: [$parse:syntax] Syntax Error: Token '-' is unexpected, expecting [}] at column 10 of the expression [{progress-bar-success:complete==='complete', progress-bar-warning:complete==='incomplete', progress-bar-danger:complete==='fail'}] starting at [-bar-success:complete==='complete', progress-bar-warning:complete==='incomplete', progress-bar-danger:complete==='fail'}].
答案 0 :(得分:2)
您可以使用ng-class ng-class =&#34; {class1:expression1,class2:expression2}&#34;
在你的情况下是这样的
<div class="progress-bar"
ng-class="{'progress-bar-success':row.entity.status==='complete', 'progress-bar-warning':row.entity.status==='incomplete', 'progress-bar-danger':row.entity.status==='fail'}">
</div>
答案 1 :(得分:0)
在你的控制器中添加它;
var myApp = angular.module('myApp');
myApp.controller('clickCtrl', function($scope){
$scope.dynamicClass = "progress";
});
在您看来:
cellTemplate : "<div ng-class="dynamicClass"> <div class="progress-bar progress-bar-info" ></div> </div>"
定义css:
.progress{
background-color: orange !important;
}
.done{
background-color: green!important;
}
答案 2 :(得分:0)
你应该使用angulars ngClass指令。
答案 3 :(得分:0)
如果您确实想要使用自己的样式,请确保不要将它们定义为&#34; .ui-grid-cell-contents&#34;它实际上适用于rowTemplate但不适用于cellTemplate。我已经看过几篇关于此的帖子,它可以为你节省一些麻烦。