【发布时间】:2014-07-31 20:11:36
【问题描述】:
您好,我正在尝试根据以下变量的值更改按钮的颜色:$scope.order.orderwindow.invoicedata。
我正在更改 ng-class 中的表达式来执行此操作。但是,尽管我有手表功能,但现在它并没有改变。
directive.js
.directive('invoicetypewatch', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
// change styling of button depending on if id is null or not
scope.$watch('order.orderwindow.invoicedata', function() {
if(scope.order.orderwindow.invoicedata.id!=null) {
scope.invoice_delete_type_button_styling={"btn btn-danger btn-block":true};
}else{
scope.invoice_delete_type_button_styling={"btn btn-danger btn-block":false};
}
});
}
};
})
view.html
<div class="col-lg-4" invoicetypewatch>
<button ng-class="{{invoice_delete_type_button_styling}}" ng-click="delete(invoice_delete_type_button,order.orderwindow.invoicedata.id)">{{invoice_delete_type_button}}</button>
</div>
【问题讨论】:
标签: javascript angularjs angularjs-directive angularjs-ng-repeat angularjs-service