私は学校のプロジェクトで助けが必要です。私は解決を必要とする問題のリストを作成し更新するためのアプリを作っています。MEANを使用してデータを保存
私は、問題が挿入されるはずの入力フィールドを持っています。そして、ID、 "Open"ステータス、および日付スタンプを生成する必要があります。
次に、出力テーブルに問題が表示されます。私はdatabasのwhatsを表示できることを解決しました。今私は新しいデータを保存する部分を解決する必要があります。
私の計画は、Addボタンをngクリックして、AddIssueという名前の関数を呼び出すことです。そして、データトラフを送信し、データ
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
サーバーを格納するのにmoongoseを使用して$ HTTPポストを使用して。 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);
これは私が来ていることがこれまでのところで、そして今私はどのように
をserver.jsするcontroller.jsからデータを送信する第一及び第二の私のMongoDB問題
:
は見てみましょう。これは、MEANスタックを使用してtodoアプリを作成するための素晴らしい記事です:https://scotch.io/tutorials/creating-a-single-page-todo-app-with-node-and-angular。 –