简体   繁体   English

使用MEAN堆栈连接到模拟数据集

[英]Connecting to a mock data set using the MEAN stack

I am experimenting with building an application using the MEAN stack. 我正在尝试使用MEAN堆栈构建应用程序。 I've managed to get as far as setting up a test page and successfully utilizing Angular.js' ability to display and re-order data based upon search criteria. 我已经设法建立了一个测试页面,并成功地利用了Angular.js的能力来根据搜索条件显示和重新排序数据。 I am interested in taking it a small step further by calling upon data stored in an external Json document using a javascript controller. 我有兴趣通过使用javascript控制器调用存储在外部Json文档中的数据将其进一步发展。 When I run the program as is everything checks out okay except for one thing; 当我按原样运行程序时,除一件事外,其他所有内容都可以正常运行; I can't seem to properly link the file. 我似乎无法正确链接文件。 I think I may not fully understand which document is meant to be treated as the root file. 我想我可能不完全了解哪个文档应被视为根文件。

My code is as fallows: 我的代码如下:

Controller.js: Controller.js:

 var phonecatApp = angular.module('contactApp', []); phonecatApp.controller('ContactListCtrl', ['$scope', '$http', function($scope, $http) { $http.get('../data/contacts.json').success( function(data) { $scope.contacts = data; }); $scope.orderProp = 'age'; }]); 

My File structure is as follows: 我的文件结构如下:

myApp
├── data
|   |-- contacts.json
├── public
│   ├── javascripts
│   │   ├── controllers
|           |---controller.js
|---views
|   |---index.jade
|   |---layout.jade

What iv'e tried: 我尝试过的是:

I read through the documentation and I believe it instructed me to write the link in my to my controller as if it were coming from the index.jade file. 我通读了文档,并相信它指示我将链接写到我的控制器中,就像它来自index.jade文件一样。 However, this didn't seem to work out the way I wanted. 但是,这似乎并没有达到我想要的方式。

Any suggestions would be greatly appreciated. 任何建议将不胜感激。

Thank You 谢谢

您必须检查设置静态目录的代码的Node.js部分(您可能使用Express,因此请检查此http://expressjs.com/starter/static-files.html ),也许它是public ,所以将data公开并称为$http.get('/data/contacts.json')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM