这非常简单:我的角度视图显示通过ng-repeat生成的printOrders行。如果打印了打印订单,则会应用“panel-pink”类
<div class="col-md-12" ng-repeat="printOrder in printOrders | filter: statuses">
<div class='panel mb20 panel-primary panel-hovered' ng-class="{'panel-pink' : {{printOrder.Printed}}}">
<div class="panel-body">
<div style="text-align: center; margin-top: 10px; margin-bottom: 10px;">
<div>{{printOrder.GcodePath}},{{printOrder.Flavor}},{{printOrder.Finishing}}</div>
</div>
<div>
<a class="btn btn-small btn-success btn-sm" ng-click="doPrintOrder(printOrder)">Print</a>
</div>
</div>
</div>
</div>
当它加载页面时,它会对打印的那些应用'panel-pink'类,但是当我通过ng-click更改printOrder状态时它不会
当用户点击“打印”按钮时,打印指令控制器上的以下代码将执行:
$scope.doPrintOrder = function (printOrder) {
PrintOrdersAPIService.printOrder(printOrder.Id, printOrder.UserId, printOrder.GcodePath).then(function (data) {
printOrder.Printed = true; //this line should change the model
});
}
一切正常,唯一的问题是当模型改变时,ng-class不会被应用(printOrder.Printed = true;)
为了使样式动态地工作,我该怎么做?
答案 0 :(得分:2)
将您的ng-class更改为:
ng-class="{'panel-pink' : printOrder.Printed}"
你不需要大括号。