按下按钮,浏览器上没有任何操作,我的REST端点上没有新用户。按下按钮触发registerUser()。我密切关注了一个教程。
html partial
<div class="section no-pad-bot" ng-controller="registerController" id="index-banner">
等等等等等等等等
<form>
<div class="row">
<div class=" input-field col s6 offset-s3">
<i class="material-icons prefix">account_circle</i>
<input type="text" class="validate" ng-model="user.username" placeholder="Username">
</div>
</div>
<div class="row">
<div class=" input-field col s6 offset-s3">
<i class="material-icons prefix">account_circle</i>
<input type="text" class="validate" ng-model="user.email" placeholder="Email">
</div>
</div>
<div class="row">
<div class=" input-field col s6 offset-s3">
<i class="material-icons prefix">account_lock</i>
<input type="text" class="validate" ng-model="user.password" placeholder="Password">
</div>
</div>
<button class="btn waves-effect waves-light" type="submit" ng-click="registerUser()">Submit
<i class="material-icons right">send</i>
</button>
</form>
在clientapp.js
中myApp.controller('registerController', function ($scope, $http) {
$scope.registerUser = function () {
// use $.param jQuery function to serialize data from JSON
var data = $.param({
hashword: $scope.password,
username: $scope.username,
email: $scope.email,
});
var config = {
headers : {
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
}
}
$http.post('/api/users', data, config)
.success(function (data, status, headers, config) {
console.log("successful post");
$scope.PostDataResponse = data;
})
.error(function (data, status, header, config) {
console.log("failed post");
$scope.ResponseDetails = "Data: " + data +
"<hr />status: " + status +
"<hr />headers: " + header +
"<hr />config: " + config;
});
};
答案 0 :(得分:2)
因为在html页面中,您指的是user.username
,'user.email'和user.password
而不是username
,email
和password
。< / p>
尝试更改为以下
<input type="text" class="validate" ng-model="username" placeholder="Username">
<input type="text" class="validate" ng-model="email" placeholder="Email">
<input type="text" class="validate" ng-model="password" placeholder="Password">
希望有所帮助