2013-09-30 99 views
1

我有一個AngularJS應用程序,我正在構建。我對Angular有點新鮮,但我一直在通過教程等。我已經到了想要通過<form>在服務器上登錄PUT數據的程度。所以,我在一起塑造了一對夫婦的角度文檔和SO帖子:

那麼,到底我有這樣的:

HTML

<form id="register-form" ng-controller="RegisterController" 
         ng-submit="registerUser()"> 
    <label>Display Name</label> 
    <input type="text" ng-model="user.displayname"></input> 
    <label>Email Address</label> 
    <input type="text" ng-model="user.username"></input> 
    <label>Password</label> 
    <input type="password" ng-model="user.password"></input> 
    <a href="#/register" class="button primary gradient" 
     onclick="$('#register-form').submit();">Register</a> 
</form> 

控制器

function RegisterController($scope) { 
    $scope.user = { }; 

    $scope.registerUser = function() { 
     $http({ 
      method: 'PUT', 
      url: '/user/register', 
      data: $scope.user 
     }).success(function(data) { 
        setAjaxMessage(data, true); 
       }).error(function(data) { 
        setAjaxMessage(data, false); 
       }); 
    }; 
} 

不過,Firefox正在執行代碼時記錄此錯誤:

Error: $http is not defined 
RegisterController/[email protected]://l.tpb.com/js/controllers.js:22 
_functionCall/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.js:6541 
ngEventDirectives[directiveName]</</</<@https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.js:13256 
[email protected]://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.js:8218 
[email protected]://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.js:8298 
ngEventDirectives[directiveName]</</<@https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.js:13255 
[email protected]://l.tpb.com/js/jquery-1.10.2.min.js:5 
x.event.add/[email protected]://l.tpb.com/js/jquery-1.10.2.min.js:5 
[email protected]://l.tpb.com/js/jquery-1.10.2.min.js:5 
.trigger/<@http://l.tpb.com/js/jquery-1.10.2.min.js:5 
[email protected]://l.tpb.com/js/jquery-1.10.2.min.js:4 
[email protected]://l.tpb.com/js/jquery-1.10.2.min.js:4 
[email protected]://l.tpb.com/js/jquery-1.10.2.min.js:5 
x.fn[t]@http://l.tpb.com/js/jquery-1.10.2.min.js:6 
[email protected]://l.tpb.com/#/register:1 

回答

7

你需要注入它

function RegisterController($scope, $http) 
+0

我知道我很親近我的朋友!非常感謝。 –

相關問題