Tran Thien Chien
Tran Thien Chien

Reputation: 681

Writing clean code in html

I want to validate a form and show error message corresponding to a validation code.

Following is my current code

<div class="alert alert-danger" ng-show="Ctrl.getValidationCode()=== Ctrl.VALIDATION_CODE['EXCEEDED_RANGE'] ">fromdate exceeded todate</div>

Is it better to use this

ng-show="Ctrl.getValidationCode()=== Ctrl.VALIDATION_CODE['EXCEEDED_RANGE']"

Or use this instead

ng-show="Ctrl.getValidationCode()=== 1"

I think the first one is better Because It's cleaner to the second one. But the first one is too long.

Could you give me your opinions and advice?

Upvotes: -1

Views: 185

Answers (2)

Grzesie2k
Grzesie2k

Reputation: 19

I think that the best way is a new directive that handle all form erros messages in your application.

Upvotes: 1

alxbxbx
alxbxbx

Reputation: 323

First one is more practical, because you can give your code some freedom. So if you use that validation code on few pages, it's lot easier to manage that code. Because if you need to change code, you will change it only on one place instead of going to separate pages. It's something like convention.

Upvotes: 1

Related Questions