2016-05-02 4 views
0

Ich habe die folgenden drei AngularJS Skripte:AngularJS Fehler: ng: areq Bad Argument

/config.js 
/authentication/LoginCtrl.js 
/authentication/loginFactoyr.js 

App ristoreApp in config.js definiert ist.

//config.js

angular.module('ristoreApp', ['ngRoute']) 

.config(function ($routeProvider, $locationProvider, $httpProvider) { 
// $httpProvider.responseInterceptors.push('httpInterceptor'); 

    $routeProvider 
     .when('/login', { 
      templateUrl: 'authentication/login.html', 
      controller: 'LoginCtrl' 
     }) 
     .when('/home', { 
      templateUrl: 'home.html', 
     }) 
     .otherwise({ 
      redirectTo: '/login' 
     }); 

    $locationProvider.html5Mode(true); 
}); 

Mein Controller ruft die App von "angular.module":

angular.module('ristoreApp', []) 
.controller('LoginCtrl', ['$scope', '$location', 'loginFactory', function($scope, $location, loginFactory){ 
    $scope.authenticate = function() { 
     loginFactory.login($scope.username, $scope.password) 
     .then(function(response) { 
      console.log(response); 
      $location.path('/home'); 
     }, function errorCallBack(response) { 
      console.log(response); 
      $location.path('login'); 
     }); 
    } 
}]); 

Haben Sie den Fehler "Fehler: ng: areq Bad Argument"

Argument 'LoginCtrl' is not a function, got undefined 

Warum sagt mein Controller keine Funktion? Was habe ich falsch gemacht?

Antwort

1

Versuchen Sie dies. Entfernen Sie die Anführungszeichen unter LoginCtrl.

controller: LoginCtrl 

Dann definieren Sie den Controller wie:

var LoginCtrl = app.controller("LoginCtrl", ["$scope", function($scope) { /* etc... */}]); 
+0

Welche Zitate entferne ich? Ich habe meinen Controller in 'app = angular.module ('ristoreApp', []) geändert; var LoginCtrol = app.controller ("LoginCtrl", ['$ scope', ... 'aber es hat nicht geholfen – ddd

+0

Sie müssen die Anführungszeichen entfernen.' Controller: 'LoginCtrl' sollte 'controller: LoginCtrl' sein – Kyle

Verwandte Themen