0

I have a view that has two modes - view and edit. I'm using angular so I will be using some directives to change the behavior of the page based on what mode it's in. I know it's common in C to #DEF some constant strings for use later. I was wondering if there is a good design pattern similar to this for use in JS. For example I will be doing something like:

    <input ng-if="mode==='edit'"></input>

Notice the string literal 'edit'

1
  • 2
    You can use Enums Commented Apr 10, 2017 at 18:07

1 Answer 1

1

Enums like Satpal suggested are indeed a nice feature in typescript. However in you're case I would suggest to just use a boolean on you component (or if the mode is app-wide maybe a service).

Your html is also much cleaner, something like this:

<input ng-if="editMode"></input>
Sign up to request clarification or add additional context in comments.

1 Comment

I think you are right. Enums seem to be a bit overkill in this situation. However I will definitely keep them in mind for the future!

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.