我正在嘗試按標題提示進行操作。問題是,我的瀏覽器沒有顯示任何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