Error: [ng:areq] Argument 'LoginCtrl' is not a function, got undefined


#1

Hi,

Its really been so frustrated, i have been stuck with this issue and gone through forum with same topics but don’t see any solution. hope someone there to help me out from this issue.

App Controller files code:

// Ionic Starter App
’use strict’;
// angular.module is a global place for creating, registering and retrieving Angular modules
// ‘starter’ is the name of this angular module example (also set in a attribute in index.html)
// the 2nd parameter is an array of 'requires’
angular.module(‘starter’, [‘ionic’])

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

  // Don't remove this line unless you know what you are doing. It stops the viewport
  // from snapping when text inputs are focused. Ionic handles this internally for
  // a much nicer keyboard experience.
  cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
  StatusBar.styleDefault();
}

});
})

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

// Ionic uses AngularUI Router which uses the concept of states
// Learn more here: https://github.com/angular-ui/ui-router
// Set up the various states which the app can be in.
// Each state’s controller can be found in controllers.js
$stateProvider

.state('login', {
  cache:false,
  url: '/login',
  templateUrl: 'templates/login.html',
  controller: 'LoginCtrl'
})

;

// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise(’/login’);

});

Controllers.js file code

‘use strict’;
angular.module(‘starter.controllers’, [])

.controller(‘LoginCtrl’, function($scope) {
console.log(‘login controller loaded’);
//$scope.data = {};

/*$scope.login = function() {
  console.log("LOGIN user: " + $scope.data.username + " - PW: " + $scope.data.password);
}*/

})

Now Index.html code is here

<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">

<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->

<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>

<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>

<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/services.js"></script>
<script src="js/controllers.js"></script>

and Login.html templates is here

Username Password Keep me Signed In Sign In No Registered yet? Sign Up

i have tried everything and stuck here and getting error is below:

Error: [ng:areq] Argument ‘LoginCtrl’ is not a function, got undefined
http://errors.angularjs.org/1.5.3/ng/areq?p0=LoginCtrl&p1=not%20a%20function%2C%20got%20undefined
minErr/<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:13438:12
assertArg@http://localhost:8100/lib/ionic/js/ionic.bundle.js:15214:11
assertArgFn@http://localhost:8100/lib/ionic/js/ionic.bundle.js:15224:3
$controller@http://localhost:8100/lib/ionic/js/ionic.bundle.js:23373:9
self.appendViewElement@http://localhost:8100/lib/ionic/js/ionic.bundle.js:59900:24
ionicViewSwitcher.create/switcher.render@http://localhost:8100/lib/ionic/js/ionic.bundle.js:57893:29
ionicViewSwitcher.create/switcher.init@http://localhost:8100/lib/ionic/js/ionic.bundle.js:57813:11
self.render@http://localhost:8100/lib/ionic/js/ionic.bundle.js:59759:5
self.register@http://localhost:8100/lib/ionic/js/ionic.bundle.js:59717:5
updateView@http://localhost:8100/lib/ionic/js/ionic.bundle.js:65398:11
.compile/</<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:65375:11
$RootScopeProvider/this.$get</Scope.prototype.$broadcast@http://localhost:8100/lib/ionic/js/ionic.bundle.js:30718:15
transitionTo/$state.transition<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:52157:11
processQueue@http://localhost:8100/lib/ionic/js/ionic.bundle.js:29127:28
scheduleProcessQueue/<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:29143:27
$RootScopeProvider/this.$get</Scope.prototype.$eval@http://localhost:8100/lib/ionic/js/ionic.bundle.js:30395:16
$RootScopeProvider/this.$get</Scope.prototype.$digest@http://localhost:8100/lib/ionic/js/ionic.bundle.js:30211:15
$RootScopeProvider/this.$get</Scope.prototype.$apply@http://localhost:8100/lib/ionic/js/ionic.bundle.js:30503:13
done@http://localhost:8100/lib/ionic/js/ionic.bundle.js:24824:36
completeRequest@http://localhost:8100/lib/ionic/js/ionic.bundle.js:25022:7
requestLoaded@http://localhost:8100/lib/ionic/js/ionic.bundle.js:24963:9

return logFn.apply(console, args);

ionic.bundle.js (line 26794)

IS THERE ANYONE WHO CAN HELP ME OUT REALLY, THANKS IN ADVANCE


#2

Heey, i think your issue is that you don’t add the starter.controllers as a dependecy too the angular module.starter, you should put it like this :
angular.module('starter', ['ionic', 'starter.controllers'])

hope it helps


#3

thanks for your reply really i appreciate, i just replaced the code you suggested and getting this issue

Error: [$injector:modulerr] Failed to instantiate module starter due to:
[$injector:modulerr] Failed to instantiate module starter.controllers due to:
[$injector:nomod] Module ‘starter.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.
http://errors.angularjs.org/1.5.3/$injector/nomod?p0=starter.controllers
minErr/<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:13438:12
module/<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:15404:17
ensure@http://localhost:8100/lib/ionic/js/ionic.bundle.js:15328:38
module@http://localhost:8100/lib/ionic/js/ionic.bundle.js:15402:14
loadModules/<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:17894:22
forEach@http://localhost:8100/lib/ionic/js/ionic.bundle.js:13691:11
loadModules@http://localhost:8100/lib/ionic/js/ionic.bundle.js:17878:5
loadModules/<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:17895:40
forEach@http://localhost:8100/lib/ionic/js/ionic.bundle.js:13691:11
loadModules@http://localhost:8100/lib/ionic/js/ionic.bundle.js:17878:5
createInjector@http://localhost:8100/lib/ionic/js/ionic.bundle.js:17800:19
bootstrap/doBootstrap@http://localhost:8100/lib/ionic/js/ionic.bundle.js:15080:20
bootstrap@http://localhost:8100/lib/ionic/js/ionic.bundle.js:15101:12
angularInit@http://localhost:8100/lib/ionic/js/ionic.bundle.js:14986:5
@http://localhost:8100/lib/ionic/js/ionic.bundle.js:44079:5
trigger@http://localhost:8100/lib/ionic/js/ionic.bundle.js:16497:7
defaultHandlerWrapper@http://localhost:8100/lib/ionic/js/ionic.bundle.js:16787:3
createEventHandler/eventHandler@http://localhost:8100/lib/ionic/js/ionic.bundle.js:16775:9

http://errors.angularjs.org/1.5.3/$injector/modulerr?p0=starter.controllers&p1=[%24injector%3Anomod]%20Module%20’starter.controllers’%20is%20not%20available!%20You%20either%20misspelled%20the%20module%20name%20or%20forgot%20to%20load%20it.%20If%20registering%20a%20module%20ensure%20that%20you%20specify%20the%20dependencies%20as%20the%20second%20argument. http%3A%2F%2Ferrors.angularjs.org%2F1.5.3%2F%24injector%2Fnomod%3Fp0%3Dstarter.controllers minErr%2F<%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A13438%3A12 module%2F<%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A15404%3A17 ensure%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A15328%3A38 module%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A15402%3A14 loadModules%2F<%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A17894%3A22 forEach%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A13691%3A11 loadModules%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A17878%3A5 loadModules%2F<%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A17895%3A40 forEach%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A13691%3A11 loadModules%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A17878%3A5 createInjector%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A17800%3A19 bootstrap%2FdoBootstrap%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A15080%3A20 bootstrap%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A15101%3A12 angularInit%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A14986%3A5 %40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A44079%3A5 trigger%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A16497%3A7 defaultHandlerWrapper%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A16787%3A3 createEventHandler%2FeventHandler%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A16775%3A9
minErr/<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:13438:12
loadModules/<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:17917:15
forEach@http://localhost:8100/lib/ionic/js/ionic.bundle.js:13691:11
loadModules@http://localhost:8100/lib/ionic/js/ionic.bundle.js:17878:5
loadModules/<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:17895:40
forEach@http://localhost:8100/lib/ionic/js/ionic.bundle.js:13691:11
loadModules@http://localhost:8100/lib/ionic/js/ionic.bundle.js:17878:5
createInjector@http://localhost:8100/lib/ionic/js/ionic.bundle.js:17800:19
bootstrap/doBootstrap@http://localhost:8100/lib/ionic/js/ionic.bundle.js:15080:20
bootstrap@http://localhost:8100/lib/ionic/js/ionic.bundle.js:15101:12
angularInit@http://localhost:8100/lib/ionic/js/ionic.bundle.js:14986:5
@http://localhost:8100/lib/ionic/js/ionic.bundle.js:44079:5
trigger@http://localhost:8100/lib/ionic/js/ionic.bundle.js:16497:7
defaultHandlerWrapper@http://localhost:8100/lib/ionic/js/ionic.bundle.js:16787:3
createEventHandler/eventHandler@http://localhost:8100/lib/ionic/js/ionic.bundle.js:16775:9

http://errors.angularjs.org/1.5.3/$injector/modulerr?p0=starter&p1=[%24injector%3Amodulerr]%20Failed%20to%20instantiate%20module%20starter.controllers%20due%20to%3A [%24injector%3Anomod]%20Module%20’starter.controllers’%20is%20not%20available!%20You%20either%20misspelled%20the%20module%20name%20or%20forgot%20to%20load%20it.%20If%20registering%20a%20module%20ensure%20that%20you%20specify%20the%20dependencies%20as%20the%20second%20argument. http%3A%2F%2Ferrors.angularjs.org%2F1.5.3%2F%24injector%2Fnomod%3Fp0%3Dstarter.controllers minErr%2F<%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A13438%3A12 module%2F<%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A15404%3A17 ensure%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A15328%3A38 module%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A15402%3A14 loadModules%2F<%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A17894%3A22 forEach%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A13691%3A11 loadModules%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A17878%3A5 loadModules%2F<%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A17895%3A40 forEach%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A13691%3A11 loadModules%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A17878%3A5 createInjector%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A17800%3A19 bootstrap%2FdoBootstrap%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A15080%3A20 bootstrap%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A15101%3A12 angularInit%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A14986%3A5 %40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A44079%3A5 trigger%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A16497%3A7 defaultHandlerWrapper%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A16787%3A3 createEventHandler%2FeventHandler%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A16775%3A9 http%3A%2F%2Ferrors.angularjs.org%2F1.5.3%2F%24injector%2Fmodulerr%3Fp0%3Dstarter.controllers%26p1%3D%5B%24injector%3Anomod%5D%20Module%20’starter.controllers’%20is%20not%20available!%20You%20either%20misspelled%20the%20module%20name%20or%20forgot%20to%20load%20it.%20If%20registering%20a%20module%20ensure%20that%20you%20specify%20the%20dependencies%20as%20the%20second%20argument.%0Ahttp%3A%2F%2Ferrors.angularjs.org%2F1.5.3%2F%24injector%2Fnomod%3Fp0%3Dstarter.controllers%0AminErr%2F%3C%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A13438%3A12%0Amodule%2F%3C%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A15404%3A17%0Aensure%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A15328%3A38%0Amodule%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A15402%3A14%0AloadModules%2F%3C%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A17894%3A22%0AforEach%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A13691%3A11%0AloadModules%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A17878%3A5%0AloadModules%2F%3C%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A17895%3A40%0AforEach%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A13691%3A11%0AloadModules%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A17878%3A5%0AcreateInjector%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A17800%3A19%0Abootstrap%2FdoBootstrap%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A15080%3A20%0Abootstrap%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A15101%3A12%0AangularInit%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A14986%3A5%0A%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A44079%3A5%0Atrigger%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A16497%3A7%0AdefaultHandlerWrapper%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A16787%3A3%0AcreateEventHandler%2FeventHandler%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A16775%3A9%0A minErr%2F<%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A13438%3A12 loadModules%2F<%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A17917%3A15 forEach%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A13691%3A11 loadModules%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A17878%3A5 loadModules%2F<%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A17895%3A40 forEach%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A13691%3A11 loadModules%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A17878%3A5 createInjector%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A17800%3A19 bootstrap%2FdoBootstrap%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A15080%3A20 bootstrap%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A15101%3A12 angularInit%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A14986%3A5 %40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A44079%3A5 trigger%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A16497%3A7 defaultHandlerWrapper%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A16787%3A3 createEventHandler%2FeventHandler%40http%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A16775%3A9

return new ErrorConstructor(message);

ionic.bundle.js (line 13438, col 12)


#4

do you include the file in your index.html ?? or can you show me index.html? or provide a codepen sample here’s an example which is kinda the same thing as you want: http://codepen.io/loringdodge/pen/vOrRpV


#5

here you got

Thanks


#6

Heyy i made it work for you :slight_smile:

study this code


#7

Thanks really , i had to make changes into App.js And controllers.js as per your code

in app.js i had to add
angular.module(‘starter’, [‘ionic’,‘starter.controllers’])

and in controllers.js i had to add this line

angular.module(‘starter.controllers’, [])

and now it works.

thanks a lot 100 times