<ion-view class="auth-view" cache-view="false">
<ion-nav-bar class="view-navigation">
<ion-nav-back-button>
</ion-nav-back-button>
</ion-nav-bar>
<ion-content class="padding">
<div class="row form-heading">
<div class="col">
<h1 class="form-title">Create your account</h1>
<h3 class="form-sub-title">Sign up with Social Network or Email</h3>
<div class="social-sign-up button-bar">
<a class="button icon ion-social-facebook button-positive"></a>
<a class="button icon ion-social-twitter button-calm"></a>
</div>
</div>
</div>
<div class="row form-separator">
<hr class="separator-line"/>
<span class="separator-mark">OR</span>
<hr class="separator-line"/>
</div>
<div class="row form-wrapper">
<div class="col">
<form name="signup_form" class="" novalidate>
<div class="form-fields-outer list list-inset">
<div class="row multi-inputs">
<div class="col">
<label class="item item-input">
<input class="multi-input" type="text" placeholder="Name" name="name" ng-model="user.name" required>
</label>
</div>
<div class="col">
<label class="item item-input">
<input class="multi-input" type="text" placeholder="Username" name="username" ng-model="user.userName" required>
</label>
</div>
</div>
<label class="item item-input">
<input type="email" placeholder="Email" name="email" ng-model="user.email" required>
</label>
<label class="item item-input">
<input type="tel" placeholder="Phone Number" name="phone" ng-model="user.phone" required>
</label>
<label class="item item-input" show-hide-container>
<input type="password" placeholder="Password" name="password" ng-model="user.password" required show-hide-input>
</label>
<button type="submit" class="sign-up button button-block" ng-click="doSignUp()" ng-disabled="signup_form.$invalid">
Sign Up
</button>
<p ng-show="error" class="message error">{{error}}</p>
</div>
</form>
</div>
</div>
</ion-content>
</ion-view>
这是我试图发布数据的代码
.controller('CreateAccountCtrl',['$scope', '$http', function($scope, $http){
$scope.doSignUp = function(){
console.log("doing sign up");
$http.post('/accounts', $scope.user).success(function (user) {
console.log(user);
});
// $state.go('app.feed');
};
}])
最后我的server.js到目前为止
var express = require('express');
var app = express();
var mongojs = require('mongojs');
var db = mongojs('accounts',['accounts']);
var bodyParser = require('body-parser');
//app.use(express.bodyParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(express.static(__dirname + "/www"));
// app.get('/accounts', function(req, res){
// // res.send("i got the request")
// db.accounts.find(function(err, docs){
// console.log(docs);
// res.json(docs);
// });
// });
app.post('/accounts', function(req, res){
// console.log(req.body.user);
db.accounts.insert(req.body.user, function(err, doc){
res.json(doc);
});
});
app.listen(3000);
console.log("server running on port 3000");
我知道有一些问题,但我只是不知道我还在学习什么。在此先感谢您的帮助
我也从mongo
遇到了这个错误TypeError: Cannot read property '_id' of undefined
at /Users/beast/node_modules/mongojs/lib/collection.js:83:19
at /Users/beast/node_modules/mongojs/lib/collection.js:20:7
at apply (/Users/beast/node_modules/thunky/index.js:16:28)
at /Users/beast/node_modules/thunky/index.js:20:25
at /Users/beast/node_modules/mongojs/lib/database.js:36:9
at /Users/beast/node_modules/mongodb/lib/mongo_client.js:519:11
at nextTickCallbackWith0Args (node.js:420:9)
at process._tickCallback (node.js:349:13)
答案 0 :(得分:0)
您的快递控制人员正在寻找身体中名为&#34; user&#34;的财产。您只是将用户对象直接传递到正文中。在角度控制器中,尝试以下操作:
.controller('CreateAccountCtrl',['$scope', '$http', function($scope, $http){
$scope.doSignUp = function(){
console.log("doing sign up");
$http.post('/accounts', { user: $scope.user}).success(function (user) {
console.log(user);
});
// $state.go('app.feed');
};
}])