简体   繁体   English

Angular 2材质选项卡 - 仅在选项卡上加载内容

[英]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. 我希望以一种方式实现Angular 2 Material选项卡,每个选项卡内容只有在相应的选项卡设置为活动时才会初始化。

This is what I use. 这就是我使用的。 https://material.angular.io/components/tabs/overview 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;
    });
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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