This section contains a login field where users can input their username, password, and click the login button. It may seem lengthy and detailed at first glance.
<form name='form' novalidate ng-submit="form.$valid && submit('/login')" ng-focus="showError=false" ng-controller='loginController' >
<h2>Login</h2>
<div class="form-group has-feedback" ng-class="{ 'has-error' : ((form.username.$touched || form.$submitted) && form.username.$invalid) || showError}">
<input ng-focus="showError=false" type="email" name="username" class="form-control" placeholder="Email" ng-model='data.username' ng-disabled="loading" required>
<span ng-show="((form.username.$touched || form.$submitted) && form.username.$invalid) || showError" class="glyphicon form-control-feedback glyphicon-remove"></span>
<p ng-show="(form.username.$touched || form.$submitted) && form.username.$invalid" class="help-block text-left">Enter a valid email</p>
</div>
<div class="form-group has-feedback" ng-class="{ 'has-error' : ((form.password.$touched || form.$submitted) && form.password.$invalid) || showError}">
<input ng-focus="showError=false" type="password" name="password" class="form-control" placeholder="Password" ng-model='data.password' ng-disabled="loading" required>
<span ng-show="( (form.password.$touched || form.$submitted) && form.password.$invalid ) || showError" class="glyphicon form-control-feedback glyphicon-remove"></span>
<p ng-show="(form.password.$touched || form.$submitted) && form.password.$invalid" class="help-block text-left">Enter a password</p>
</div>
<button type="submit" class="btn btn-primary btn-block" ng-disabled="loading">
Log in</button>
</form>
Repetitive use of expressions like the one below:
((form.username.$touched || form.$submitted) && form.username.$invalid) || showError
Is there an efficient way to reduce the code length in this scenario? Are there any recommended practices?