【发布时间】:2016-10-07 13:43:04
【问题描述】:
我想保存从表单 (html) 中获取的数据。 我的表单中有相同的文件,我想将它们从 html 页面发送到 node.js 页面,然后从那里发送到 mongoDB (mlab) 数据库。 在我的节点页面中,我使用 angular 来保存从用户表单中获取的数据。 我正在使用 ng-controller 连接到 js 页面,并使用 ng-model 来保存我在输入标签中获得的数据。 我的问题是我无法将数据保存在 mongoDB 中?
谢谢,
html:
<body ng-controller="addController">
<h1 class="text-center">Add Activity</h1>
<form class="form-group" ng-submit="createActivity()">
<div class="form-group">
<div class="col-sm-10">
<label for="inputEmail3" class="col-sm-2 control-label">Title:</label>
<input class="form-control" type="text" placeholder="Title" ng-model="title"></input>
</div>
<div class="col-sm-10">
<label for="inputEmail3" class="col-sm-2 control-label">Age:</label>
<input class="form-control" id="inputEmail3" type="number" placeholder="Age" ng-model="age" min="0" max="16"></input>
</div>
<div class="col-sm-10">
<label for="inputEmail3" class="col-sm-2 control-label">Description:</label>
<textarea class="form-control" id="inputEmail3" type="text" placeholder="Description" ng-model="description"></textarea>
<br>
</div>
<div class="col-sm-10">
<label for="inputEmail3" class="col-sm-2 control-label">Themes:</label>
<input type="radio" name="themes" value="frozen" ng-model="theme">frozen
<input type="radio" name="themes" value="minions" ng-model="theme">minions
<input type="radio" name="themes" value="heroes" ng-model="theme">heroes
<input type="radio" name="themes" value="princess" ng-model="theme">princess
<input type="radio" name="themes" value="piraets" ng-model="theme">piraets
<input type="radio" name="themes" value="none" ng-model="theme">none
<br>
</div>
<div class="col-sm-10">
<br>
<input type="file" name="upload" ng-model="image"></input>
</div>
<div class="col-sm-10">
<br>
<input type="submit" class="btn btn-default" name="send"></input>
</div>
</div>
</form>
js:
var addActivityApp = angular.module('addActivityApp',['$scope','$resource']);
var Activity = $resource('/activities');
var activity = new Activity();
$scope.createActivity=function () {
var activity = new Activity();
activity.title = $scope.title;
activity.age = $scope.age;
activity.description = $scope.description;
activity.theme = $scope.theme;
activity.$save(function (result) {
$scope.activities.push(result);
$scope.title = '';
$scope.age = '';
$scope.description = '';
$scope.theme = '';
});
});
addActivityApp.controller('addController',function($scope) {
$scope.addController = model;
});
【问题讨论】:
-
您与 mongoDB 的连接在哪里?
-
我的连接是从服务器说这是我的客户说的。
标签: javascript html angularjs node.js mongodb