There is no such event, but if you use a tab control, the right way to do this is to create a @Output
tab @Output
for your tab control if it is executed in normal mode, otherwise most tab controls (e.g. ng-bootstrap ) also have a tab change event.
If your component needs to know about this, you can use this tab change event to determine which tab is visible, and if you know which tab is visible, you also know whether your component is visible or not. So you can do something like this:
onTabChange(event) { this.currentTab = ; }
And then you can send it to the component itself if you have input:
@Input() activated: boolean = false;
And then you can apply it with:
<my-component [activated]="currentTab == 'tabWithComponent'"></my-component>
Now you can listen to OnChanges
to see if the activated
model value has changed to true
.
You can also reorganize this to use the service with Observable
as follows:
@Injectable() export class TabService { observable: Observable<any>; observer; constructor() { this.observable = Observable.create(function(observer) { this.observer = observer; }); } }
When a component wants to listen to these changes, it can subscribe to tabService.observable
. When your tab changes, you can click on it with new elements using tabService.observer.next()
.
source share