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>
[{"日期" : "3月16日星期四", "数据1" : "样本子项", "Data2" : "样本类", "日期" : "下午6:29", "image1" : "E:\Event\www\img\img2.jpg", "文本" : "老虎的故事", "image2" : "E:\Event\www\img\img5.jpg" },{"日期" : "3月14日星期二", "数据1" : "样本子项", "Data2" : "样本类", "日期" : "12:43 pm", "image1" : "E:\Event\www\img\img6.jpg", "文本" : "老虎的故事", "image2" : "E:\Event\www\img\img4.jpg" },{"日期" : "3月10日星期五","数据1" : "样本子项","Data2" : "样本类","日期" : "12:03 pm", "image1" : "E:\Event\www\img\img1.jpg", "文本" : "老虎的故事", "image2" : "E:\Event\www\img\img4.jpg" }]
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;
});
}])
<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>