Module Error in AngularJS

2

I can not understand and fix this error. I'm using ionic.

  

Uncaught Error: [$ injector: modulerr] Failed to instantiate module   inparty due to: Error: [$ injector: modulerr] Failed to instantiate   module inparty.controllers due to: Error: [$ injector: nomod] Module   'inparty.controllers' is not available! You either misspelled the   module name or forgot to load it. If registering a module ensure that   you specify the dependencies as the second argument.

angular.module('inparty.controllers', [])

.controller('AppCtrl', function($scope, $ionicModal, $timeout) {
  // Form data for the login modal
 $scope.loginData = {};

  // Create the login modal that we will use later
  $ionicModal.fromTemplateUrl('templates/login.html', {
   scope: $scope
  }).then(function(modal) {
$scope.modal = modal;
 });

// Triggered in the login modal to close it
    $scope.closeLogin = function() {
    $scope.modal.hide();
 };

 // Open the login modal
   $scope.login = function() {
    $scope.modal.show();
  };

   // Perform the login action when the user submits the login form
  $scope.doLogin = function() {
     console.log('Doing login', $scope.loginData);

    // Simulate a login delay. Remove this and replace with your login
    // code if using a login system
   $timeout(function() {
      $scope.closeLogin();
   }, 1000);
};
})

 .controller('PlaylistsCtrl', function($scope,$http) {
     $scope.dados = Array();

    $http.get("js/dados.php").success(function(data){
        $scope.dados = data.dados;
        console.log($scope.dados);
    }).error(function(data){
        alert("Error...");
        console.log(data);
    });
})

.controller('PlaylistCtrl', function($scope, $stateParams) {
 var idParaEncontrar = $stateParams.id;
console.log(idParaEncontrar);
var objectoEncontrado = undefined;

               for(var i = 0; i < $scope.dados.length: ++i){
            if($scope.dados[i].id === idParaEncontrar) {
                objectoEncontrado = $scope.dados[id];
            break;
            }
            }
if(objectoEncontrado !== undefined) {
    console.log("objecto encontrado")
  } 
 });

app.js

angular.module('inparty', ['ionic', 'inparty.controllers','ngRoute'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
   // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
     // for form inputs)
    if (window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
   }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
   }
  });
})

.config(function($stateProvider, $urlRouterProvider) {
   $stateProvider

  .state('app', {
    url: "/app",
    abstract: true,
    templateUrl: "templates/menu.html",
    controller: 'AppCtrl'
 })

 .state('app.search', {
   url: "/search",
    views: {
     'menuContent': {
        templateUrl: "templates/search.html"
      }
    }
  })

  .state('app.browse', {
     url: "/browse",
   views: {
      'menuContent': {
        templateUrl: "templates/browse.html"
      }
   }
  })
   .state('app.playlists', {
     url: "/playlists",
      views: {
        'menuContent': {
          templateUrl: "templates/playlists.html",
          controller: 'PlaylistsCtrl'
        }
      }
   })

 .state('app.single', {
    url: "/playlists/:id",
    views: {
     'menuContent': {
        templateUrl: "templates/playlist.html",
        controller: 'PlaylistCtrl'
      }
    }
 });
  // if none of the above states are matched, use this as the fallback
  $urlRouterProvider.otherwise('/app/playlists');
});
    
asked by anonymous 04.03.2015 / 15:55

2 answers

2

According to the error description, it seems that the inparty.controllers module is not yet loaded / set when the angle starts its bootstrap.

Test the following changes:

app.js

var inpartyControllers = angular.module('inparty.controllers', []);

angular.module('inparty', ['ionic', 'inparty.controllers','ngRoute'])    
.run(function($ionicPlatform) {
// Seu código continua aqui.

And when you set your control consume the reference to the initialized module, like this:

inpartyControllers 
.controller('AppCtrl', function($scope, $ionicModal, $timeout) {
  // Form data for the login modal
 $scope.loginData = {};
 // Seu código continua aqui.
    
04.03.2015 / 16:10
1

Friend, try to use the definition of the non-angular module normally, it may be giving modules redundancy:

angular.module('inparty.controllers', [])

try to put this in your "controllers.js" file.

Delete the line:

inpartyControllers
    
03.04.2015 / 17:14