【发布时间】:2017-04-28 07:01:33
【问题描述】:
我在学校项目方面需要帮助。我正在制作一个应用程序来创建和更新需要解决的问题列表。
我有一个输入字段,我应该在其中插入问题,然后它应该生成一个 ID、一个“打开”状态和一个日期戳。
然后问题将显示在我的输出表中。我已经解决了我可以显示数据库中的内容。现在我需要解决我存储新数据的部分。
我的计划是在我的按钮 AddIssue 上使用 ng-click 并调用一个也名为 AddIssue 的函数。然后使用 $http post 发送数据槽,然后使用 moongose 存储数据
HTML
<div ng-controller="inputCtrl">
<p>New issue <input class="form-control" type="text" ng-model="newIssue"></p>
<button ng-click="AddIssue()"> Add </button>
</div>
<div ng-controller="tableCtrl">
<table class="table table-striped">
<thead>
<tr>
<th>Status</th>
<th>Issue</th>
<th>Date</th>
<th>ID</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="issue in issueList">
<td>{{issue.status}}</td>
<td>{{issue.issue}}</td>
<td>{{issue.date}}</td>
<td>{{issue.id}}</td>
</tr>
</tbody>
</table>
</div>
我的 JS 文件 controller.js
var myApp = angular.module('myApp', []);
// Controller for input
myApp.controller('inputCtrl', function($scope) {
// Call function when click on AddIssue btn
$scope.AddIssue = function() {
console.log("Click click....")
// Use Post to send data to database
$http.post('/issueList').sucess( function(response){
$scope.newIssue = 'New issue';
})
}
}); // End of input
server.js
/* Connect to db issues */
mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost/issues');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
/* Connect to MongoDB */
db.once('open', function (callback) {
console.log("Connected to db");
// Created b-schema
issueSchema = mongoose.Schema({
id: String,
issue: String,
date: String,
status: String
});
// Create Model
Issue = mongoose.model('Issue', issueSchema );
到目前为止,我已经来了,现在我需要帮助,首先如何将数据从 controller.js 发送到 server.js
第二次使用 mongoose 将其存储在我的 mongodb 问题上
【问题讨论】:
-
我认为你应该看一些例子来帮助你。这是一篇关于使用 MEAN 堆栈创建待办事项应用程序的好文章:scotch.io/tutorials/…。
标签: angularjs mongodb express mongoose mean