Ich möchte die Daten speichern, die ich von meinem Formular (html) bekomme. Ich habe die gleichen Dateien in meinem Formular und möchte sie von der HTML-Seite zur node.js-Seite und von dort zur mongoDB (mlab) -Datenbank senden. In meiner Knotenseite benutze ich eckig, um die Daten zu speichern, die ich vom Benutzer bekomme. Ich verwende ng-Controller, um eine Verbindung zur js-Seite herzustellen, und benutze ng-model, um die Daten zu speichern, die ich in der Eingabe-Bezeichnung erhalte. Mein Problem ist, dass ich die Daten in MongoDB nicht speichern kann?Speichern Sie Daten aus dem Formular
Danke,
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;
});
vereinfachen Wo ist Ihre Verbindung zu mongoDB? –
meine Verbindung ist vom Server sagte das ist mein Client sagte. – adi