Skip to content

Cannot read property 'getSubs' of undefined.

Harshal Thakre

Harshal Thakre

Asked Jul 14, 2017, 4:52 AM EDT1 answer
Share
LinkedInX
AngularScript?v=Sn4qt-PnIXwAS34HPmPOJw1QPMEWLxfWx5TyWFOzC2g1:1 TypeError: Cannot read property 'getSubs' of undefined
 Note: When i use bundle(Minify) then it gets stuck otherwise works properly
 
My Code :
 
Controller.JS Code :
 
JavaScript
var app;
(function () {
    app = angular.module("APICourseModule", []);

})();
app.controller('APICourseController', ['$scope', function ($scope, APICourseService) {
 getAll();
JavaScript
    function getAll() {

        var servCall = APICourseService.getSubs();
        servCall.then(function (d) {
            $scope.course = d;},
 function (error) {console.log('Oops! Something went wrong while fetching the data.')});
}
}]); 
 
Service.js code:- 
  
 app.service("APICourseService", ['$http',function ($http) {
JavaScript
    this.getSubs = function () {
        var url = 'api/Course';
        return $http.get(url).then(function (response) {return response.data;});
    }
}]); 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Harshal Thakre
    0
    Solution:
    Controller.js
     
    JavaScript
    var app = angular.module("APICourseModule", []);
        app.controller('APICourseController', ['$scope', 'APICourseService', function ($scope, APICourseService) {
            $scope.loading = true;
    
            getAll();
            function getAll() {
    
                var servCall = APICourseService.getSubs();
                servCall.then(function (d) {
                    $scope.course = d;
                    $scope.loading = false;
                }, function (error) {console.log('Oops! Something went wrong while fetching the data.')});
    
    }
        }]);
    
    
    
    Services:
      app.service("APICourseService", ['$http', function ($http) {
    
     }]);
    0