app.controller('MyClassController', ['$scope', 'config','$http', 'auth','$location','$routeParams', function($scope, config, $http, auth, $location, $routeParams){ var vm = $scope; var courseid = $routeParams.id; vm.currentTab = 1; vm.tab = function(index){ vm.currentTab = index; vm.searchText = ''; console.log(vm.currentTab); if(index == 2){ if(vm.students.length<=0){ $http.get(config.apiUrl + 'courses/students?token='+auth.token()+'&course_id='+courseid).then( function(response) { console.log(response.data); vm.students = response.data.data; } ) } } } vm.course = {}; vm.students = []; vm.teachers = []; vm.resources = []; vm.invite = function(){ $location.path("/invite_code").search({id: courseid}); }; $http.post(config.apiUrl + "courses/"+courseid+"/attachments", {token: auth.token(), name: ''} ).then(function(response){ vm.resources = response.data.data; }); $http.get(config.apiUrl+ 'courses/'+courseid+"?token="+auth.token()).then( function(response){ console.log(response.data); vm.course = response.data.data; } ); if(vm.teachers.length<=0){ $http.get(config.apiUrl + 'courses/teachers?token='+auth.token()+'&course_id='+courseid).then( function(response) { console.log(response.data); vm.teachers = response.data.data; } ) } }]);