我想使用ng-dirty来应用样式来在角度应用中形成元素;但是,还有另一个我要比较的条件,以确定是否应该应用脏样式。换句话说,如果ng-dirty为true,则应用脏样式和另一个条件为真(scope.myVar!= null或类似的东西)。
我意识到我也可以用ng-class完成这项任务,但想知道是否有替代品。
答案 0 :(得分:1)
我会在输入字段中添加一个条件ng-class,而不是编辑ng-dirty
类。在您检查数据(例如myVar
)不为空($scope.myVar != null
)的情况下,我会采取以下措施:
<input ng-model="myVar" ng-class="{ 'custom-condition' : myVar != null }"/>
然后,在CSS中,您将看到BOTH类(ng-dirty和您的custom-condition
)当前是否已应用于该元素。
// If both .ng-invalid and .custom-condition are applied:
.ng-dirty.custom-condition {
border: 1px solid red;
}