I have an angular function like this:
$scope.colorValidator = function () {
$scope.token_style = "";
$scope.expdate_style = "";
if (!$scope.$$childHead.billingblock.accountID.$valid) {
$scope.token_style = {border: "1px solid #ff0000"}
}
if (!$scope.$$childHead.billingblock.expDate.$valid) {
$scope.expdate_style = {border: "1px solid #ff0000"}
}
};
How can i set the {border: "1px solid #ff0000"} in a constant variable (maybe like red), and set it in each validation ?
Edit: I'm setting ng-style (in the view) for each input.
.valid-fieldand using the JavaScript to apply that as necessary. Styles belong in stylesheets, not in code.$scope.expdate_style = 'valid-field'?.ng-invalid. See @vittore's answer.