Ionicの使い方を覚えていて、現在localhostを使ってアプリケーションをテストしています。私は連絡先リストアプリケーションを作成しようとしています。名前、電子メール、連絡先電話番号、アバターなどの連絡先情報はJSONファイルからロードされます。しかし、何も現れず、コンソールでのクローム・エラー・メッセージが、これは言う:「リソースの読み込みに失敗しました:サーバーは、404の状態(見つかりません)と答えた」:IonicアプリでJSONファイルを読み込めません
ここは私のindex.htmlファイルであります
angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.controller('myController', function($scope,$http){
$http.get('js/addressbook.json').success(function(data){
$scope.data = data;
})
})
マイaddressbook.jsonファイルは私のapp.jsファイルも配置されている「JS」フォルダ内に配置されています。ここ
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<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>
</head>
<body ng-app="starter">
<ion-pane ng-controller-"myController">
<ion-header-bar class="bar-dark">
<button class="button button-clear icon ion-navicon"></button>
<h1 class="title">Friends List</h1>
<button class="button button-clear icon ion-settings"></button>
</ion-header-bar>
<div class="bar bar-subheader item-input-inset">
<label class="item-input-wrapper">
<i class="icon ion-search placeholder-icon"></i>
<input type="text" placeholder="Search"/>
</label>
</div>
<ion-content class="has-subheader">
<div class="list">
<div class="item item-thumbnail-left" ng-repeat="element in data.persons">
<img src="{{ element.personDisplayPicture }}"/>
<h2>{{ element.personName }}</h2>
<p>{{ element.personContact }}</p>
<p>{{ element.personEmail }}</p>
</div>
</div>
</ion-content>
</ion-pane>
</body>
</html>
そして、私のapp.jsファイルです。 、私はあなたのコードは問題ないと思います
{"persons": [
{
"personContact": "+91-9997725251",
"personDisplayPicture": "https://fbcdn-sphotos-b-a.akamaihd.net/hphotos-ak-xtf1/v/t1.0-9/1509974_10205886752870556_6275779368926452443_n.jpg?oh=d407cc6c85c581f4ee96cd65ea15a171\u0026oe=55ECD16C\u0026__gda__=1443235524_024ba60447125011575b739fb45d23c4",
"personEmail": "[email protected]",
"personName": "Samarth Agarwal"
},
{
"personContact": "+91-",
"personDisplayPicture": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xfp1/v/t1.0-1/p160x160/10997379_828487523879435_5609581450404507062_n.jpg?oh=109f958adce1bb72754ed1772e598893&oe=56276727&__gda__=1441608268_136ec1af8e25e4364909decbd724f26a",
"personName": "Apoorva Agarwal",
"personEmail": "[email protected]"
}
]}
try '$ http.get( 'file:///android_asset/www/js/addressbook.json')' –