I have an angular material application with multiple tabs. I am trying not to load all the data at once. I would like to load the data which is needed for the current tab only. What is the best way to achieve this.I have a controller for the whole page and directives with controllers for every tab. I tried to use onTabChanges event but the directives don't catch this event
HTML CODE
<div ng-controller="AdminController as ctrl" class="md-content" ng-cloak>
<md-tabs flex md-dynamic-height md-border-bottom md-stretch-tabs="auto">
<md-tab label="One" md-on-select="onTabChanges(1)">
<tab-One></tab-One>
</md-tab>
<md-tab label="Two" md-on-select="onTabChanges(2)">
<tab-Two></tab-Two>
</md-tab>
<md-tab label="Three" md-on-select="onTabChanges(3)">
<tab-Three></tab-Three>
</md-tab>
</md-tabs>
</div>
JS CODE
<script>
MyApp.controller('AdminController', function ($scope) {
$scope.onTabChanges = function (currentTabIndex) {
$scope.globalVar = currentTabIndex;
}
}
MyApp.directive('tabOne', function ($location) {
return {
restrict: 'E',
transclude: true,
templateUrl: "../HtmlTemplates/one.html",
controller: function ($scope, $http) {
if ($scope.globaVar === 1) {
Do something
}
}
}
}
</script>