title: Changing Input Element CSS based on Angular Reactive Forms validation
body: <p><strong>I have a simple reactive form like this:</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>this.loginForm = this._fb.group({
    email: ['', [Validators.required, Validators.pattern('^[A-Za-z0-9._%+-]+@gmail.com$')]],
    password: ['', Validators.required]
  });
  </code></pre>
  
  <p><strong>The on HTML:</strong></p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;!------------------------- PASSWORD FIELD -------------------------&gt;
  &lt;div class="uk-margin"&gt;
    &lt;input type="password" class="uk-input"
           placeholder="Enter Password" formControlName="password"&gt;
  
    &lt;!----- VALIDATION WARNINGS -----&gt;
    &lt;div *ngIf="loginForm.get('password').touched"&gt;
      &lt;div *ngIf="loginForm.get('password').hasError('required')"&gt;
        &lt;div class="uk-text-danger"&gt; Password is required.&lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Then in CSS:</strong></p>
  
  <pre class="lang-css prettyprint-override"><code>.ng-valid[required] {
     border: 5px solid #42A948;
   }
  
  .ng-invalid[required] {
     border: 5px solid red; 
   }
  </code></pre>
  
  <p>The <code>ng-valid/invalid</code> CSS is being applied. I want to change the colour of the input fields border. But the CSS does not work form me. What am I doing wrong? </p>
  
  <p>Update:</p>
  
  <p><a href="https://i.stack.imgur.com/W3jX8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/W3jX8.png" alt="enter image description here"></a></p>