Angularjs 使用Angular JS将数据插入MongoDB
我试图将一些用户输入数据插入数据库,而不是mySQL,我决定使用MongoDB。这是我的输入表格 form.htmlAngularjs 使用Angular JS将数据插入MongoDB,angularjs,mongodb,Angularjs,Mongodb,我试图将一些用户输入数据插入数据库,而不是mySQL,我决定使用MongoDB。这是我的输入表格 form.html <div class="row" ng-controller="formController"> <form class="form-inline"> <input class="form-control" name="userName" placeholder="Name"><br> <input clas
<div class="row" ng-controller="formController">
<form class="form-inline">
<input class="form-control" name="userName" placeholder="Name"><br>
<input class="form-control" name="email" placeholder="E-mail"><br>
<input class="form-control" name="phone" placeholder="Phone"><br>
<input class="form-control" name="address" Placeholder="Address">
<input type="submit" class="btn btn-primary" value="Add">
</form>
</div>
如何使用angular将这些值插入MongoDB?
注意:formController为空,其中没有代码 访问MongoDB与MySQL没有太大区别。您需要某种库来帮助您连接到它(就像我所知道的所有SQL数据库一样)。为此,您可能需要一个后端来处理表单提交,如@cbass所述 还可以看看一些restful方法
我不知道任何PHP,所以我不能帮助。但是看看这个:因为Mongo没有一个普通的http接口,所以您需要一个后端适配器,比如节点的Mongoose,或者带有prostrgres(Rails)的ActiveRecord 想到ElasticSearch,有些“数据库”具有Restful JSON接口。弹性搜索并不是我所考虑的一个记录数据库系统,但我试图指出,您需要一个HTTP/JSON层来接受您的请求并将数据推送到数据库中。 如果您对JS非常了解,一定要尝试一下Mongoose/Express/Node。对于任何真正的应用程序,您都需要一个合适的后端,而节点是一个容易启动的地方 这是我唯一讨厌Stackoverflow的部分。这里的人们考虑 在发布问题之前,您应该了解所有信息 考虑到您对Angular(就像我以前一样)是新手,让我们澄清一些要点:
var app = angular.module('myapp');
.controller('lister', ['$http', function($http) {
var self = this;
$http.get('http://localhost:3000/testCollection')
.then(function(response) {
self.items = response.data;
}, function(errResponse) {
console.error('Error while fetching menus' + errResponse);
});
}]);
您需要某种类型的服务器,不能直接从客户端写入数据库。请更具体一些!Angular是一个前端框架。它不能插入MongoIs,在没有后端的情况下插入是可能的吗?这可能与PHP重复吗?我修改了我的答案,看看上面。希望它能给你一个提示。