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
2 Answers
Reset to default 3You 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
版权声明:本文标题:javascript - How to connect mongoDB to angular2 app? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741857196a2401413.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论