我正在构建一个AngularJS应用程序。而且我对Angular有点新,但我一直在研究教程等。我已经达到了PUT
通过<form>
在服务器上<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>
数据的程度。所以,我把几个Angular文档和一个SO帖子组合在一起:
所以,最后我有这个:
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);
});
};
}
Error: $http is not defined
RegisterController/$scope.registerUser@http://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
Scope.prototype.$eval@https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.js:8218
Scope.prototype.$apply@https://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
x.event.dispatch@http://l.tpb.com/js/jquery-1.10.2.min.js:5
x.event.add/v.handle@http://l.tpb.com/js/jquery-1.10.2.min.js:5
x.event.trigger@http://l.tpb.com/js/jquery-1.10.2.min.js:5
.trigger/<@http://l.tpb.com/js/jquery-1.10.2.min.js:5
.each@http://l.tpb.com/js/jquery-1.10.2.min.js:4
x.prototype.each@http://l.tpb.com/js/jquery-1.10.2.min.js:4
.trigger@http://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
onclick@http://l.tpb.com/#/register:1
但是,Firefox在执行该代码时会记录此错误:
{{1}}
答案 0 :(得分:7)
你需要注射它
function RegisterController($scope, $http)