admin管理员组

文章数量:1308161

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

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

Any inputs?

Thanks in advance.

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

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

Any inputs?

Thanks in advance.

Share Improve this question asked Jul 1, 2016 at 5:28 Bhushan GadekarBhushan Gadekar 13.8k21 gold badges88 silver badges131 bronze badges 2
  • 1 Hi Bhushan, I believe till now you have implemented mongo and angular2. I have a small question, by reading the answers below I understood, to implement mongo with angular to I have to run another server, like nodejs or expressjs for connection with mongo/creating a rest service. and the lite server of angular 2 cant handle the connection. Is this correct understanding? – Arijit Commented Feb 10, 2017 at 13:26
  • @Arijit Lite server will eventually run the front end. node servers like express,loopback are good options to go with. – Bhushan Gadekar Commented Feb 11, 2017 at 8:13
Add a ment  | 

2 Answers 2

Reset to default 3

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./blog/2014/10/01/creating-a-restful-api-tutorial-with-nodejs-and-mongodb/

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.

You should use a server side framework like hapijs, expressjs etc where you have to make a connection by mentioning your database url like

`mongodb://username:[email protected]:12367/dbName

which then connects your app to database.

本文标签: javascriptHow to connect mongoDB to angular2 appStack Overflow