我正在接收
Uncaught TypeError:ReferenceError:annonces未定义。我的离子应用程序的某个页面的充电错误。
我想发送" annonce"的ID在详细信息页面中选择以列出此项目的所有详细信息
重新加载页面后出现错误。 enter image description here 我现在应该怎么做才能解决这个问题:/
service.js
angular.module('starter.services', [])
.factory('Annonces', function($http, $q) {
// Might use a resource here that returns a JSON arra
var dfd = $q.defer();
$http.get("/php/annonces.php").then(function(response){
annonces = response.data;
console.log(annonces);
dfd.resolve(annonces);
});
return {
all: function(){
return dfd.promise;
},
get: function(annonceId) {
$http.get("/php/annonces.php").then(function(response){
annonces = response.data;
});
for (var i = 0; i < annonces.length; i++) {
if (annonces[i].id === parseInt(annonceId)) {
console.log(annonces[i]);
return annonces[i];
}
}
return null;
}
};
&#13;
controller.js
angular.module('starter.controllers', [])
.controller('AnnoncesCtrl', function($scope, allannonces) {
$scope.annonces = allannonces;
})
.controller('AnnonceDetailCtrl', function($scope, $stateParams, Annonces) {
$scope.annonce = Annonces.get($stateParams.annonceId);
console.log($scope.annonce);
});
&#13;
app.js
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('annonces', {
url: '/annonces',
templateUrl: 'templates/annonces.html',
controller: 'AnnoncesCtrl',
resolve: {
allannonces: function(Annonces) {
return Annonces.all(); }
}
}
)
.state('details', {
url: '/annonces/:annonceId',
templateUrl: 'templates/details.html',
controller: 'AnnonceDetailCtrl'
}
)
$urlRouterProvider.otherwise('/annonces');
});
&#13;
annonce.html
<ion-list>
<ion-item class="item item-thumbnail-left item-remove-animate item-icon-right" ng-repeat="annonce in annonces|filter:searshing" type="item-text-wrap" href="#/annonces/{{annonce.id}}">
<img ng-src="{{annonce.img}}">
<h2>{{annonce.titre}}</h2>
<p>{{annonce.prix}}</p>
<p>{{annonce.description}}</p>
<p>{{annonce.date_creation}} {{annonce.region}}</p>
<i class="icon ion-chevron-right icon-accessory"></i>
</ion-item>
</ion-list>
&#13;
details.html
<div class="item item-divider" style="white-space: normal;padding: 4px;">
<span style="padding-bottom: 4px;text-transform: uppercase;font-weight:bold;color:#346f96;font-size: 12px;">{{annonce.titre}}</span>
<div style="display: block">
<span style="color:#666; font-size: 10px;">{{annonce.date_creation}} {{annonce.region}} </span>
<span style="color: #ff942a;font-weight: bold;margin-bottom: 5px;padding:4px;font-size: 14px; position: absolute;right: 0px;">
{{annonce.prix}}
</span>
</div>
</div>
&#13;