AngularJS | Conditional Class using ng-class
问题 I'm wanting to apply a conditional class to an element on the page. Currently it's working with the following code: ng-class="{ 'vfnz-form--error' : loginForm.username.$invalid } This applies a invalid class if the input field is invalid. I'm wanting to apply a " valid" class when the user input field is valid. Is this possible to achieve in the same line of code? Here is a fiddle example: JSFIDDLE 回答1: You could just do it in many ways, one simple way would be to use an object with bracket