title: Angular 5 change tab on validation error
body: <p>Hi there i need to complete a validation system for my Angular 5 app. i have 3 tabs on my page, like this:</p>
  
  <pre><code>&lt;mat-tab-group *ngIf="action=='edit'"
      (selectedTabChange)="tabChanged($event)"
      [(selectedIndex)]="selectedTabIndex" dynamicHeight="true"&gt;
          &lt;mat-tab label="Dati"&gt; &lt;/mat-tab&gt; 
          &lt;mat-tab label="Metodi"&gt; &lt;/mat-tab&gt; 
          &lt;mat-tab label="Immagini"&gt; &lt;/mat-tab&gt; 
  &lt;/mat-tab-group&gt;
  </code></pre>
  
  <p>In controller component i have a method save() when the first tab is not completed it show error on a dialog and hilight in red the needed fields. I want that even if the check on secon tab return error the label of TAB become red and page move on this tab.</p>
  
  <p>Here is my function</p>
  
  <pre><code>save(form) {
  const state = this.ngRedux.getState();
  console.log(this.user.form);
  //extract files for upload
  //this.prepareImageUpload();
  console.log(this.user.form)
  this.formDisabled = form;
  this.saving = true;
  //  form.disable();
  
  this.loading = this.help.loading();
  
  this.usersActions.saveAndReturn(this.user.form).subscribe(response =&gt; {
    console.log(response);
    let user = response.data;
    if (this.user.form.conti == '') {
      this.help.alert({
        title: 'Error',
        subtitle: 'Occorre completare la sezione conti per poter salvare',
        cancel: {
          name: 'Annula'
        }
      });
    }
    else if (this.user.form.paymentmethods == '') {
      this.help.alert({
        title: 'Error',
        subtitle: 'Occorre completare la sezione modalità di pagamento per poter salvare',
        cancel: {
          name: 'Annula'
        }
      });
    } else {
      if (state.session.fakeUser) {
        if (state.session.fakeUser.id == user.id) {
          this.usersActions.updateConti(user.conti);
          this.usersActions.updatePayment(user.paymentmethods);
        }
      } else {
        if (state.session.user.role == 'user') {
          this.usersActions.updateConti(user.conti);
          this.usersActions.updatePayment(user.paymentmethods);
        }
      }
  
  
      if (this.user.form.logo &amp;&amp; typeof this.user.form.logo != 'string') {
        this.usersProvider.uploadFile(user.id, this.user.form.logo.file, 'logo').subscribe(
          resp =&gt; {
            //  console.log(resp);
          }
        )
      }
    }
  
    this.loading.close();
  
    if (state.session.user.role == 'admin') {
      if(this.userSubscribe){
        this.userSubscribe.unsubscribe();
      }
      if(this.lookupSubscribe){
        this.lookupSubscribe.unsubscribe();
      }
  
  
  
        this.router.navigateByUrl('clienti-studio');
    }
  },
    error =&gt; {
      this.loading.close();
      this.help.alert({
        title: 'Error',
        list: error.validation,
        cancel: {
          name: 'Annula'
        }
      });
    }
  
  );
  </code></pre>
  
  <p>}</p>