Module error in Angularjs

Asked

Viewed 655 times

2

I cannot understand and correct this error. I am 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');
});

2 answers

2

According to the description of the error, it seems to me that the module inparty.controllers is not yet loaded/set when angular starts 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, thus:

inpartyControllers 
.controller('AppCtrl', function($scope, $ionicModal, $timeout) {
  // Form data for the login modal
 $scope.loginData = {};
 // Seu código continua aqui.
  • Blz apparently right and I could understand why of this more unfortunately happened to occur this error ... Argument 'Appctrl' is not a Function, got Undefined

  • @Matheusmonteiro in which part? When you configure your routes?

  • I can’t tell you I’m a little lost ... follow the code of how you got your changes .... http://pastebin.com/ZU3aqXh3 http://pastebin.com/vaEwXdwf

  • @Matheusmonteiro Can I take a look at Exception too? It would help a lot

  • follow the project .. https://mega.co.nz/#! lEIxXS4I! xy3eG0g60y5VoUKC2rN3bqeRyLruYuEcKA76MAHpom0

1

Friend, try to normally use the module setting at the angle, it may be giving modules redundancy:

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

try putting this in your "controllers.js file".

Delete the line:

inpartyControllers
  • Also try not to create the "inpartyControllers" function, leave it aside for now.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.