2015-04-21 248 views
0

以下是我在AngularJS中的代碼。我創建了控制器,但我得到的錯誤:角度控制器錯誤

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

app.controller("forgetController", function ($scope, forgetService) { 
    $scope.OperType = 1; 
    // 1 MEANS NEW ENTRY 

    GetAllUserRecords(); 


    function GetAllUserRecords() { 
     debugger; 
     var promiseGet = userService.GetUserRecords(); 
     promiseGet.then(function (p1) { $scope.User = p1.data }, function (err) { 
      console.log("Error"); 
     }); 
    } 

    $scope.submit = function() { 
     debugger; 
     var user = { 
      FirstName: $scope.FirstName, 
      LastName: $scope.LastName, 
      Email: $scope.Email, 
      Password: $scope.Password, 
      Phone: $scope.Phone, 
      Postcode: $scope.Postcode, 
      Address: $scope.Address, 
      Street: $scope.Street, 
      Town: $scope.Town, 
      CreateDate: new Date() 
     }; 
     if ($scope.OperType === 1) { 
      var promisePost = userService.AddUser(user); 
      promisePost.then(function (p1) { 
       GetAllUserRecords(); 
       alert("New Record Inserted"); 
       $("#addUserTable").css('display', 'none'); 
       clearClientDetail(); 
      }, function (err) { 
       console.log("Error"); 
      }); 
     } 
    } 

    function clearClientDetail() { 
     $("#FirstName").val(''); 
     $("#LastName").val(''); 
     $("#Email").val(''); 
     $("#Password").val(''); 
     $("#Phone").val(''); 
     $("#Postcode").val(''); 
     $("#Address").val(''); 
     $("#Street").val(''); 
     $("#Town").val(''); 
    } 
}); 

我堅持過來,我谷歌的一切,但我沒有得到任何結果。

+0

哪裏userService? 不應該傳入userService而不是forgetService嗎? 也檢查這個答案: [錯誤:ng:areq](http://stackoverflow.com/questions/25895235/angularjs-error-ngareq-argument-homecontroller-is-not-a-function-got-und) – worker11811

+0

你可以發佈你的模塊初始化的問題。意思是'var myApp = angular.module('myApp');' – Arulkumar

回答

0

添加此行的代碼只是上面的控制器代碼

var app = angular.module('myapp', ['forgetService']);