简体   繁体   中英

Angular 2 material tabs - content loading on tab active only

Just a simple question. I want to implement Angular 2 Material Tabs in a way that each tab content it is initialized only when the corresponding tab is set to active.

This is what I use. https://material.angular.io/components/tabs/overview

I've done this, and works for me

export class TabComponent implements OnInit {
  private tabs = {
    selectedIndex: 0
  };
  constructor() { }

  ngOnInit() {
    this.getData(0);
  }

  selectChange($event: MdTabChangeEvent) {
    this.getData($event.index);
  }

  getData(index) {
    Observable
     .create(observer => setTimeout(() => observer.next(index), 0))
     .subscribe(index => {
      this.tabs[index] = true;
    });
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM