问题描述
我试图建立一个基本的MEAN堆栈的应用程序和我得到真搞不清楚如何显示存储在MongoDB中在前端的信息。什么是建立FO使数据库查询,然后显示,在意见的过程。如果服务器是使该数据库请求和角度显示的信息?在所有我一直在寻找通过的MongoDB和角/前端之间的相互作用的教程似乎是非常有雾。
I am trying to build a basic MEAN stack app and am getting really confused about how to display information stored in mongodb in front end. What is the established process fo making a database query and then displaying that in the views. Should the server be making the db request and angular display the information? In all of the tutorials I have been looking through the interaction between mongodb and angular / front end seems to be very foggy.
目前,(因为我建立一个网球梯子应用程序)我只是想通过查询数据库中该信息显示玩家的索引页的列表中。这是正确的做法?
At the moment (as i am setting up a tennis ladder app) I just want to display the list of players on the index page by querying the database for that information. Is this the correct approach?
对于含糊不清的问题道歉,但我真的很努力理解这是如何实现的。我一直在使用Rails最近的比较(虽然他们显然非常不同),并在这种情况下,你可以使用ActiveRecord查询DATABSE并定义一个变量的查询结果,然后使用该变量在视图中显示的数据...
Apologies for the vague question but i am really struggling to understand how this is achieved. I have been using Rails recently as comparison (though obviously very different) and in that case you could query the databse using ActiveRecord and define a variable to the result of that query, then use that variable in your view to display the data...
推荐答案
要了解有关Angular.js的第一件事是,它是一个燎页面框架,而不是一个完整的页面刷新(多页)框架。所以,如果你从服务器获取动态数据,有两种方法可以做到这一点。
The first thing to understand about Angular.js is that it is a singe page framework and not a full page refresh (multi-page) framework. So if you are fetching dynamic data from the server, there are two ways to do this.
- 您可以从服务器上获取部分HTML片段,或
- 您可以从服务器获取JSON
或者你可以(在内容和JSON对数据的静态部分使用谐音)做这两者的组合。后者是做事的最Angular.js的方式 - 你获取JSON数据,并使用Angular.js数据绑定更新HTML
Or you can do a combination of the two (use partials for the static portions of the content and JSON for the data). The latter is the most Angular.js way of doing things - you fetch JSON data and use the Angular.js data binding to update the HTML.
我建议你首先要成为非常熟悉Angular.js。有很多的教程在那里,这个例子将引导您完成创建使用约曼的。这会帮助你理解的概念更好。
I would suggest that you begin by becoming very familiar with Angular.js. There are a lot of tutorials out there and this example will walk you through creating a MEAN application using Yeoman http://www.ibm.com/developerworks/library/wa-mean1/index.html. This should help you understand the concepts better.
这篇关于MEAN堆栈 - 从MongoDB的在前端显示信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!