Is it possible to use Angular to apply a class to a form field after it has been edited? The issue arises when trying to set the class name as a variable value rather than a string. Below are two code snippets - one that works and one that doesn't.
A ) This works:
<select ng-model="testModel"
ng-options="foo for foo in someList"
ng-change="testSwitch = 1"
ng-class="{'some-classname' : testSwitch }">
B ) This also works:
<select ng-model="testModel"
ng-options="foo for foo in someList"
ng-change="testSwitch = 1"
ng-class="{testVar}">
where:
$scope.testVar = 'some-classname';
C ) But this does not:
In view:
<select ng-model="testModel"
ng-options="foo for foo in someList"
ng-change="testSwitch = 1"
ng-class="{testVar : testSwitch }">
Does anyone know why this is happening or have any other possible solutions?