我的观点:
block content
.container-fluid(ng-controller='SignUpController')
.panel.panel-default
.panel-heading
.panel-title
h3 Sign Up
.panel-body
#signupbox.mainbox.col-md-6.col-md-offset-3.col-sm-8.col-sm-offset-2
form#signupform.form-horizontal(role='form')
.form-group(style='padding-top:30px')
label.col-md-3.control-label(for='firstname') First Name
.col-md-9
input.form-control(type='text', ng-model='user.first_name', placeholder='First Name')
.form-group
label.col-md-3.control-label(for='lastname') Last Name
.col-md-9
input.form-control(type='text', ng-model='user.last_name', placeholder='Last Name')
在上面代码的末尾,我有一个执行'register()'的按钮。
我的控制器将是:
var app = window.angular.module('appname', [])
app.controller('SignUpController', function ($scope, User) {
$scope.newUser = function () {
$scope.user = new User({
first_name: user.first_name
last_name: user.last_name
email: user.email
company: user.company
industry: user.industry
phone_number: user.phone_number
password: user.password
source: user.source
})
}
$scope.register = function () {
//code
$scope.user.$save().then(function () {$scope.newUser})
}
我的模特:
var mongoose = require('mongoose')
var Schema = mongoose.Schema
var db = require('../config/db')
var UserSchema = new Schema({
first_name: String,
last_name: String,
email: String,
company: String,
industry: String,
phone_number: String,
password: String,
source: String
})
var User = db.model('User', UserSchema)
module.exports = User
我的数据库配置:
var mongoose = require('mongoose')
mongoose.Promise = global.Promise
var db = mongoose.connect(process.env.DB_CONN)
module.exports = db
当我点击执行register()的按钮时,没有任何反应?我想将该用户添加到我的模型中。