Seeking a more efficient way to apply conditional classes to multiple elements on a validation form page, I am exploring options to assign one of five potential classes to each form input. While the traditional method involves manually specifying the class for each input element like so...
<input class="form-control" ng-model="form.input1" type="text" placeholder="Something here" ng-class="{class1: appliedClass('input1') == 1, class2: appliedClass('input1') == 2, class3: appliedClass('input1') == 3, class4: appliedClass('input1') == 4, class5: appliedClass('input1') == 5}" />
This approach can become cumbersome and less maintainable, especially when considering adding a sixth possible class in the future.
The question then arises - is it possible to dynamically apply a class provided by a controller function which returns the appropriate class name?
Though I came across this solution, it appears outdated and unsuccessful with my current version. Attempts using
ng-attr-class='controller_function_who_returns_a_class_name()'
have failed to evaluate the function as intended.
Any suggestions or alternative approaches to achieve this functionality?