本文介绍了如何将mongoDB连接到angular2应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 angular2& mongoDB 已配置。
到目前为止,我能够使用http服务读取json文件,但我想开发一个完整的应用程序,它也具有数据库连接。

I have angular2 & mongoDB configured.So far I am able to read json files using http service but I want to develop a complete application which will have database connectivity too.

所以我想要要知道如何配置我的angular2应用程序,以便它可以与数据库交互。

So i would like to know how can I configure my angular2 app so that it can interact with the database.

任何输入?

提前致谢。

推荐答案

您应该使用ExpressJS等框架来处理与数据库的交互,该数据库返回JSON数据就像你目前使用静态文件一样。

You should utilise a framework such as ExpressJS to handle the interaction with the database which returns JSON data in the same way as you are currently doing with a static file.

有很多教程可以解释如何执行此操作,例如

There are quite a few tutorials around which explain how to do this such as http://adrianmejia.com/blog/2014/10/01/creating-a-restful-api-tutorial-with-nodejs-and-mongodb/

你有另一个选择就是使用一个框架,在建筑物周围进行大量繁重的工作API。 是一个很好的开始,因为他们有一个生成器,可以生成客户端代码与您的API进行交互实现比自己构建一切容易得多。我有一段时间没用过它,所以我不确定他们是否还有ng2作为客户端生成器,但它可能是一个很好的起点。

The other option you have is to use a framework to do much of the heavy lifting around building the API. Loopback is a good start for such a task as they have a generator which can generate client side code to interact with your API making the implementation much easier than building everything yourself. I haven't used it in a while so I'm not sure if they have ng2 as a client side generator yet, but it might be a good place to start.

这篇关于如何将mongoDB连接到angular2应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 19:50
查看更多