2016-08-26 16 views
8

Miałem do czynienia z takim problemem, kiedy dodałem kontroler do mojego kodu trasy, nie udało się uzyskać nieoczekiwanego identyfikatora. Nie mam pojęcia dlaczego tak się dzieje To jest mój routeProvider:Nieoczekiwany identyfikator podczas dodawania kontrolera do ngRoute

app.config(function($routeProvider) { 
     $routeProvider 
      .when("/login", { 
      title: 'Login', 
      templateUrl: 'assets/login.html' 
      controller: authCtrl 
     }) 
    }); 

I to jest mój kontroler:

app.controller('authCtrl', function ($scope, $rootScope, $routeParams, $location, $http, Data) { 
    //initially set those objects to null to avoid undefined error 
     $scope.login = {}; 
     $scope.signup = {}; 
     $scope.doLogin = function (customer) { 
     Data.post('login', { 
      customer: customer 
     }).then(function (results) { 
      Data.toast(results); 
     if (results.status == "success") { 
      $location.path('dashboard'); 
     } 
     }); 
     }; 
     $scope.signup = {email:'',password:'',name:'',phone:'',address:''}; 
     $scope.signUp = function (customer) { 
     Data.post('signUp', { 
      customer: customer 
     }).then(function (results) { 
     Data.toast(results); 
     if (results.status == "success") { 
      $location.path('dashboard'); 
      } 
     }); 
     }; 
     $scope.logout = function() { 
     Data.get('logout').then(function (results) { 
     Data.toast(results); 
     $location.path('login'); 
     }); 
     } 
    }); 

podaję takich ścieżek w moim HTML:

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"/> 
    <script src="app/angular-route.min.js"></script> 
    <script src="app/angular-animate.min.js" ></script> 
    <script src="app/toaster.js"></script> 
    <script src="app/app.js"></script> 
+0

pominięcia przecinek ',' po kluczu templateUrl –

Odpowiedz

2

Tam to kilka literówek w Twoim kodzie:

app.config(function($routeProvider) { 
     $routeProvider 
      .when("/login", { 
      title: 'Login', 
      templateUrl: 'assets/login.html', // <---- missing ',' 
      controller: 'authCtrl' // <----- should be format to string 
     }) 
    }); 

Nie jestem pewien, czy to rozwiąże Twój problem.

1

Wypróbuj.

app.config(function($routeProvider) { 
     $routeProvider 
      .when("/login", { 
      title: 'Login', 
      templateUrl: 'assets/login.html', 
      controller: 'authCtrl' // <-- string 
     }) 
    }); 
1

nazwa kontroler musi uchodzić za string..try to

app.config(function($routeProvider) { 
    $routeProvider 
     .when("/login", { 
     title: 'Login', 
     templateUrl: 'assets/login.html', 
     controller: 'authCtrl' 
    }) 
}); 
Powiązane problemy