I don't really know what you want to implement and what "lazy load" means for you... Do you want to load data asynchronously before displaying the tab? As @TGH stated, routing is a great feature you should consider, especially its @CanActivate decorator:
You could consider to use a load attribute that corresponds to an Observable. The latter would wait for the observable to receive events asynchronously to be displayed.
Here is the new content of your app component:
@Component({
selector: 'my-app',
template: `
<tabs>
<tab [tabTitle]="'Tab 1'" [load]="tabLoader">Tab 1 Content</tab>
<tab tabTitle="Tab 2">Tab 2 Content</tab>
</tabs>
`,
directives: [Tabs, Tab]
})
export class App {
constructor() {
this.name = 'Angular2';
this.tabLoader = Observable.create((observer) => {
setTimeout(() => {
observer.next();
}, 1000);
});
}
}
And the update within the Tabs component:
@Component({
(...)
})
export class Tabs implements AfterContentInit {
(...)
displayTab(tab) {
// deactivate all tabs
this.tabs.toArray().forEach(tab => tab.active = false);
// activate the tab the user has clicked on.
tab.active = true;
}
selectTab(tab: Tab) {
if (tab.load) {
tab.load.subscribe(() => {
this.displayTab(tab);
});
} else {
this.displayTab(tab);
}
}
}
Here is the corresponding plunkr: https://plnkr.co/edit/d54CzKLrJirjkA6TDBC0?p=preview.
Hope it helps you,
Thierry