我正在尝试按标题提示进行操作。问题是,我的浏览器没有显示任何json文件。它应该相当直接,但我似乎无法知道哪里出了问题。如何使用angularJS在json文件中显示数据?
这里是我的app.controller.js
var app = angular.module('myApp', []);
app.controller('appCtrl', function($scope, $http) {
$http.get('data.json').success(function(data){
$scope.display = data;
});
});
而且我有一个单独的HTML文件
<html ng-app ="myApp">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<script type='text/javascript' src="bower_components/angular/angular.js" charset="UTF-8"></script>
<script type='text/javascript' src="app/app.controller.js" charset="UTF-8"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
</head>
<body ng-controller="appCtrl">
<h2> Message Display </h2>
<table>
<tr>
<th> Title </th>
<th> abstract </th>
<th> source </th>
<th> publihsed time </th>
</tr>
<tr ng-repeat = "item in display">
<td> {{item.title}} </td>
<td> {{item.abstract}} </td>
<td> {{item.source}} </td>
<td> {{item.publish_time}} </td>
</tr>
</table>
</body>
</html>
而且我确信,每个文件是在正确的目录。但就不是浏览器仅显示标签截图JSON结构的
我使用$节点server.js 这是server.js
var express = require('express');
var app = express();
app.use(express.static(__dirname));
app.get('/', function(req, res){
res.redirect('/index.html');
});
app.listen(8080);
你可以发布你的json结构吗?也有可能您的视图比响应返回 – Yaser
您提交错误更快?页面看起来像什么? – Jpsh
我没有收到错误。即使在将“显示中的数据”中的数据设置为其他内容之后,我仍然不会在json文件中获取我应该显示 – Kat