Angular 4 Material Tabs Load on Tab Select

前端 未结 4 1041
失恋的感觉
失恋的感觉 2021-01-03 04:51

Is it possible to achieve lazy loading on Angular Material Tabs? Otherwise I would need a way to run a method when entering a tab.

4条回答
  •  死守一世寂寞
    2021-01-03 05:23

    You can use the selectChange event provided by . It fires when a tab selection is changed. From the documentation:

    @Output() selectChange : Event emitted when the tab selection has changed.

    In your template:

    
      Content 1
      
        This tab will load some morecontents after 5 seconds.
        

    {{ moreContents }}

    ... and in your typescript code:

    tabSelectionChanged(event){
        // Get the selected tab
        let selectedTab = event.tab;
        console.log(selectedTab);
    
        // Call some method that you want 
        this.someMethod();
    }
    

    Link to working demo.

提交回复
热议问题