at first you need to create a service called SwitchTabService to achive communication between components.
import { Injectable, EventEmitter } from '@angular/core';
@Injectable()
export class SwitchTabService{
public onRegisterFinish = new EventEmitter();
}
add that service to the app.module.ts providers
...
providers: [
...
SwitchTabService
...
]
...
you can use the two-way data-binding as follows:
signIn.component.html file
<md-tab-group [(selectedIndex)]='currentSelectedIndex'>
<md-tab label="signin"></md-tab>
<md-tab label="register"></md-tab>
<md-tab-group>
and inside the signIn.component.ts file
import {Component, OnInit} from '@angular/core';
import { SwitchTabService } from '??';
@Component({
...
})
export class SignInComponent implements OnInit{
currentSelectedIndex;
signInIndex = 0; // assuming the index of signIn tab is 0 or the first
constructor(private switchTabService: SwitchTabService) {}
ngOnInit() {
this.switchTabService.onRegisterFinish.subscribe( () => {
this.onRegisterFinished();
});
}
onRegisterFinished() {
this.currentSelectedIndex = this.signInIndex;
// this will change the selected tab to signIn tab.
}
}
in the register.component
import {Component, EventEmitter} from '@angular/core';
import { SwitchTabService } from '??';
@Component({
...
})
export class RegisterComponent{
constructor( private switchTabService: SwitchTabService) {}
onSubmitForm() {
// you submit Logic
this.switchTabService.onRegisterFinish.emit();
}
}