内容的栏目 * @param int $category 0列表 1频道 2单页 3外链 * @return array */ function category_list($forumlist, $model = 0, $display = 0, $category = 0) { if (empty($forumlist)) return NULL; static $cache = array(); $key = $model . '-' . $display . '-' . $category; if (isset($cache[$key])) return $cache[$key]; if ($display) { foreach ($forumlist as $k => $val) { if (1 == $val['display'] && 1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } else { foreach ($forumlist as $k => $val) { if (1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } return empty($cache[$key]) ? NULL : $cache[$key]; } /** * @param $forumlist 所有版块列表 不分模型 * @param int $display 0全部CMS栏目 1在首页和频道显示内容的栏目 * @param int $category 0列表 1频道 2单页 3外链 * @return array */ function category_list_show($forumlist, $display = 0, $category = 0) { if (empty($forumlist)) return NULL; static $cache = array(); $key = $display . '-' . $category; if (isset($cache[$key])) return $cache[$key]; if ($display) { foreach ($forumlist as $k => $val) { if (1 == $val['display'] && 1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } else { foreach ($forumlist as $k => $val) { if (1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } return empty($cache[$key]) ? NULL : $cache[$key]; } /** * @param $forumlist 所有版块列表 * @return mixed BBS栏目数据(仅列表) 尚未开放bbs频道功能 */ function forum_list($forumlist) { if (empty($forumlist)) return array(); static $cache = array(); if (isset($cache['bbs_forum_list'])) return $cache['bbs_forum_list']; $cache['bbs_forum_list'] = array(); foreach ($forumlist as $_fid => $_forum) { if ($_forum['type']) continue; $cache['bbs_forum_list'][$_fid] = $_forum; } return $cache['bbs_forum_list']; } // 导航显示的版块 function nav_list($forumlist) { if (empty($forumlist)) return NULL; static $cache = array(); if (isset($cache['nav_list'])) return $cache['nav_list']; foreach ($forumlist as $fid => $forum) { if (0 == $forum['nav_display']) { unset($forumlist[$fid]); } } return $cache['nav_list'] = $forumlist; } ?>javascript - How to connect mongoDB to angular2 app? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to connect mongoDB to angular2 app? - Stack Overflow

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论