var app = angular.module('Event', ['ionic']);
app.controller('ExhibitionTabCtrl', ['$scope', '$http', function($scope,$http) {
$http.get("data.json")
.success(function (response)
{
$scope.names = response;
});
}]);
$scope.questions = [];
$http
.get("data.json")
.then(function(response){
$scope.questions = response.data.questions;
});
}])

<link rel="manifest" href="manifest.json">
<link rel="manifest" href="data.json">
<!-- un-comment this code to enable service worker
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('service-worker.js')
.then(() => console.log('service worker installed'))
.catch(err => console.log('Error', err));
}
</script>-->
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/controller.js"></script>
</head>
<body ng-app="starter">
<ion-pane>
<ion-header-bar class="bar-stable">
<!--<h1 class="title">Ionic Blank Starter</h1>-->
<button class="button button-small">
Back
</button>
<input type="text" placeholder="Search" data-ng-model="searchForce" style="margin-left:70%;">
<button ng-if="searchForce.length"
class="button button-icon ion-android-close input-button"
ng-click="clearSearch()">
</button>
</ion-header-bar>
<ion-content class="padding" ng-controller="ExhibitionTabCtrl">
<p> sample.date</p>
</ion-content>
</ion-pane>
</body>
</html>
&#13;
[ { &#34;日期&#34; :&#34; 3月16日星期四&#34;, &#34;数据1&#34; :&#34; Sample Child&#34;, &#34;数据2&#34; :&#34;样本类&#34;, &#34;日期&#34; :&#34;下午6点29分&#34;, &#34;图像1&#34; :&#34; E:\ Event \ www \ img \ img2.jpg&#34;, &#34;文本&#34; :&#34; Tiger Tale&#34;, &#34;图像2&#34; :&#34; E:\ Event \ www \ img \ img5.jpg&#34; }, { &#34;日期&#34; :&#34; 3月14日星期二&#34;, &#34;数据1&#34; :&#34; Sample Child&#34;, &#34;数据2&#34; :&#34;样本类&#34;, &#34;日期&#34; :&#34; 12:43 pm&#34;, &#34;图像1&#34; :&#34; E:\ Event \ www \ img \ img6.jpg&#34;, &#34;文本&#34; :&#34; Tiger Tale&#34;, &#34;图像2&#34; :&#34; E:\ Event \ www \ img \ img4.jpg&#34; }, { &#34;日期&#34; :&#34; 3月10日星期五&#34;, &#34;数据1&#34; :&#34; Sample Child&#34;, &#34;数据2&#34; :&#34;样本类&#34;, &#34;日期&#34; :&#34; 12:03 pm&#34;, &#34;图像1&#34; :&#34; E:\ Event \ www \ img \ img1.jpg&#34;, &#34;文本&#34; :&#34; Tiger Tale&#34;, &#34;图像2&#34; :&#34; E:\ Event \ www \ img \ img4.jpg&#34; }]
答案 0 :(得分:0)
将data.json插入www文件夹后尝试此操作。它工作正常。您可以从data.json文件中读取数据。
var app = angular.module('Event', ['ionic']);
app.controller('ExhibitionTabCtrl', ['$scope', '$http', function($scope,$http) {
$http.get("data.json")
.success(function (response) {
$scope.names = response;
});
}])
&#13;
<html>
<head>
<link rel="manifest" href="manifest.json">
<link rel="manifest" href="data.json">
<!-- un-comment this code to enable service worker
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('service-worker.js')
.then(() => console.log('service worker installed'))
.catch(err => console.log('Error', err));
}
</script>-->
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/controller.js"></script>
</head>
<body ng-app="starter">
<ion-pane>
<ion-header-bar class="bar-stable">
<!--<h1 class="title">Ionic Blank Starter</h1>-->
<button class="button button-small">
Back
</button>
<input type="text" placeholder="Search" data-ng-model="searchForce" style="margin-left:70%;">
<button ng-if="searchForce.length"
class="button button-icon ion-android-close input-button"
ng-click="clearSearch()">
</button>
</ion-header-bar>
<ion-content class="padding" ng-controller="ExhibitionTabCtrl">
<p ng-repeat="number in names">{{number.Data1}}</p>
</ion-content>
</ion-pane>
</body>
</html>
&#13;