New to angular and typescript.
I have typescript enum as follows
public enum MyEnum{
A = 0,
B = 1,
C = 2
}
A scope variable as-
$scope.myLetter: MyEnum = MyEnum.B;
What is the correct way to put the enum check?
Option 1: Compare the integer value of enum in html page-
<div ng-class="{classA: myLetter === 0, classB: myLetter === 1, classC: myLetter === 2}">Test panel</div>
Option 2: Get the class name from the controller scope method
$scope.getClass(value: myLetter): string{
if(value === MyEnum.A)
return 'classA';
if(value === MyEnum.B)
return 'classB';
if(value === MyEnum.C)
return 'classC';
}
And to have html element as-
<div ng-class='getClass(myLetter)'>Test panel</div>
Option 3: answer given by 'RyanNerd' at Angular.js and ng-switch-when - emulating enum
For me option 2 is preferable, remaining options have checks in ng-class value as string, which will not give us static type enforcement. Please share your views or any other better option if you have.