表单值更新使用Angular js,Node Js,express js和Mongo DB

我是全新的平均和工作的演示项目,我可以使用Nodejs,Express,AngularJS和MongoDB执行基本的CRUD活动,但在更新期间面临问题。

我不知道如何使用Angular js ng-click来调用MongoDB更新查询。 我可以从下面的截图中显示的Mongo DB中获取数据。

但是,如果用户对值进行任何更改并按提交,我想要更新这些值。 我正在使用ng-click进行更新。

我试了两天,但没有find任何解决scheme,我查了几个例子,但发现他们有不同的方法。

任何帮助将不胜感激

Html查看:

在这里输入图像说明

HTML查看代码:

<table cellspacing="0" cellpadding="0" border="0" id="id-form" ng-app="app-setting" ng-controller="SettingController" > <tbody><tr> <th valign="top">Facebook Link:</th> <td><input type="text" class="inp-form" ng-model="settings.facebook"></td> <td></td> </tr> <tr> <th valign="top">Twitter Link:</th> <td><input type="text" class="inp-form" ng-model="settings.twitter"></td> </tr> <tr> <th valign="top">Google+:</th> <td><input type="text" class="inp-form" ng-model="settings.googleplus"></td> <td></td> </tr> <tr> <th valign="top">Youtube:</th> <td><input type="text" class="inp-form" ng-model="settings.youtube"></td> <td></td> </tr> <tr> <th valign="top">Email:</th> <td><input type="text" class="inp-form" ng-model="settings.email"></td> <td></td> </tr> <tr> <th valign="top">Contact #:</th> <td><input type="text" class="inp-form" ng-model="settings.contactnumber"></td> <td></td> </tr> <tr> <th>&nbsp;</th> <td valign="top"> <input type="submit" class="form-submit" value="update" ng-click="update(settings)"> </td> <td></td> </tr> </tbody></table> <!-- end id-form --> 

控制器:

 .module('app-setting') .controller('SettingController',SettingController); function SettingController($scope, $http ) { $scope.page = "Setting"; $http.get('/admin/get-setting-list') .then(function(res){ $scope.settings = res.data; }); $scope.update = function(data){ //what will be here }; 

路线:

  var Setting = require('../models/setting').Setting; router.put('/admin/setting/:id', function(req, res, next) { Setting.findAndModify(req.params.id,req.body, function (err, post) { if (err) return next(err); user:res.json(post); }); 

});

型号:

  var mongoose = require('mongoose'); var Schema = mongoose.Schema; var adminService = new Schema({ facebook: String, youtube: String, googleplus: String, twitter:String, email:String, contactnumber:String, created: {type: Date, default: Date.now} }); var Setting = mongoose.model('Setting', adminService); module.exports = { Setting : Setting }; 

那么,你的HTML调用更新方法,并将设置对象传递给它,angular度控制器中看起来不错。

通过查看你的node.js代码,你需要调用

$ http.put('/ admin / setting /:id',….)在settingController中

ref: https : //docs.angularjs.org/api/ng/service/ $ http

你需要了解http方法http://www.w3schools.com/tags/ref_httpmethods.asp