Refresh tab content Angular material

2.6k Views Asked by At

I am building a web page with tabs using angular material. When I refresh the contents of particular tab ( by a refresh button on the tab ) is there a way to refresh the contents in that tab?

Since I couldn't find a solution to above I made all the tabs refreshed. Then the problem was I couldn't make the tab I am in selected. It always selected the first tab when the page refreshed.

This is in my HTML

...
    <md-tabs md-dynamic-height md-border-bottom md-selected="selectedIndex">
               <md-tab data-ng-repeat="stats in statList" label="{{stats.env}}">

...

This is in my controller where I set the selectedIndex

   $scope.refresh = function (env) {

        $log.debug(" selected index " + $scope.selectedIndex);

        var currentTabIndex = $scope.selectedIndex;

        $scope.dataLoading = true;

        requeueService.getStats()
            .success(function (data) {
                $scope.statList = data;
                $scope.dataLoading = false;
            })
            .error(function (message) {
                $scope.error = message;
                $scope.dataLoading = false;
            })

        $scope.selectedIndex = currentTabIndex;
        $log.debug("set selected index to " + currentTabIndex );

    }

Can I get an answer to either of these two questions.

1

There are 1 best solutions below

0
On

can you try it like this way

requeueService.getStats()
            .success(function (data) {
                $scope.statList = data;
                $scope.dataLoading = false;
                $scope.selectedIndex = currentTabIndex;
            })
            .error(function (message) {
                $scope.error = message;
                $scope.dataLoading = false;
            });

i think the problem is there is no tab index loaded for currentTab and directive sets it to 0 ...