我正在尝试向' UserID',' UserName'添加值。这些是子文档' NetworkList' with:控制器中的 this.NetworkList.UserID 。使用该中断表单提交,控制台中没有错误。
表单提交时,会添加 ID 的值。
模式:
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var NetworkSchema = new Schema({
Id: {
type: Number,
default: '',
trim: true
},
NetworkList: {
UserID: {
type: Number,
default: '',
trim: true
},
UserName: {
type: String,
default: '',
trim: true
}
},
});
mongoose.model('Network', NetworkSchema);
控制器:
angular.module('networks').controller('NetworksController', ['$scope', '$stateParams', '$location', 'Authentication', 'Networks',
function($scope, $stateParams, $location, Authentication, Networks) {
$scope.authentication = Authentication;
// Create new Network
$scope.create = function() {
// Create new Network object
var network = new Networks ({
Id: this.Id,
UserID: this.NetworkList.UserID,
UserName: this.NetworkList.UserName,
network.$save(function(response) {
$location.path('networks/' + response._id);
// Clear form fields
$scope.Id = '';
$scope.UserID = '';
$scope.UserName = '';
}, function(errorResponse) {
$scope.error = errorResponse.data.message;
});
};
});
形式:
<section data-ng-controller="NetworksController">
<div class="page-header">
<h1>New Network</h1>
</div>
<div class="col-md-12">
<form class="form-horizontal" data-ng-submit="create()" novalidate>
<fieldset>
<div class="form-group">
<label class="control-label" for="Id">ID</label>
<label class="control-label" for="UserID">UserID</label>
<label class="control-label" for="UserName">UserName</label>
<div class="controls">
<input type="text" data-ng-model="Id" id="Id" class="form-control" placeholder="ID" required>
<input type="text" data-ng-model="NetworkList.UserID" id="UserID" class="form-control" placeholder="UserID" required>
<input type="text" data-ng-model="NetworkList.UserName" id="UserName" class="form-control" placeholder="UserName" required>
</div>
</div>
<div class="form-group">
<input type="submit" class="btn btn-default">
</div>
<div data-ng-show="error" class="text-danger">
<strong data-ng-bind="error"></strong>
</div>
</fieldset>
</form>
</div>