Uncaught ReferenceError: MainCategoriesListController is not defined error is coming

170 Views Asked by At

The error:

MainCategoriesListController is not defined 

is coming at its declaration only ,i.e, angular.module().controller(~~,~~).

Also, in categories state, in the resolve property when i try to log the result.data it says:

  TypeError: Cannot read property 'data' of undefined

Here is my controller:

(function () {
'use strict';

angular.module('MenuApp')
.controller('MainCategoriesListController',MainCategoriesListController);


MainCategoriesListController.$inject = ['items'];
function MainShoppingListController(items) {
  var category = this;
  category.items = items;
}

})();

And here are the states :

(function () {
'use strict';

angular.module('MenuApp')
.config(RoutesConfig);

RoutesConfig.$inject = ['$stateProvider', '$urlRouterProvider'];
function RoutesConfig($stateProvider, $urlRouterProvider) {

// Redirect to home page if no other URL matches
$urlRouterProvider.otherwise('/');

// *** Set up UI states ***
$stateProvider

// Home page
.state('home', {
url: '/',
templateUrl: 'src/shoppinglist/templates/home.template.html'
})

// Categories list page
.state('categories', {
  url: '/categories',
  templateUrl: 'src/shoppinglist/templates/main-categories.template.html',
  controller: 'MainCategoriesListController as category',
  resolve: {
    items: ['MenuDataService', function (MenuDataService) {
      var promise= MenuDataService.getAllCategories();
      promise.then(function (result) {
        console.log("items : ",result.data);
      })
    }]
  }
});
}
})();

And here is my service:

(function () {
'use strict';

angular.module('data')
.service('MenuDataService',MenuDataService);

MenuDataService.$inject=['$http'];
function MenuDataService($http) {
    var service=this;

    service.getAllCategories=function () {
        var response=$http({
            method: "GET",
            url: "https://davids-restaurant.herokuapp.com/categories.json"
        })
        .then(function (result) {
            console.log("Categories  : ",result.data);
        });
        //console.log("getAllCategories data : ",response.data);
        return response;
    }
})();

data is another module and it is defined as dependency for MenuApp module. Both these are modules are declared in separate files. All components are defined in separate files.

Please help me with the solution to this problem.

0

There are 0 best solutions below