6

I have an Enum in typescript:

 enum EnumCountries{
     Canada=0,
     USA=1,
     Holland=2
} 

In AngularJS I wish to use this in the HTML, but the following doesn't work:

 <div ng-show="model.country==EnumCountries.USA">

I'm trying to get away from magic numbers in the HTML

1
  • 1
    You need to assign your enum class to a $scope variable - $scope.EnumCountries = EnumCountries Commented Jun 12, 2018 at 16:15

1 Answer 1

7

In order to use Enum in the HTML you need to specify an Enum as a variable.

You can do something like this in the component.ts:

enumCountries = EnumCountries;

And then in the component.html you can do:

<div ng-show="model.country == enumCountries.USA">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.