0
Ionicのアプリをやっています。Ionic AppのAngularJSでデータを表示する際にエラーが発生しました
services.js
angular.module('starter.services', [])
.factory('Chats', function($http) {
// Might use a resource here that returns a JSON array
var factory = {
chats: null,
all: function() { return chats; },
get: function(chatId) {
for (var i = 0; i < chats.length; i++) {
if (chats[i].id === parseInt(chatId)) {
return chats[i];
}
}
return null;
}
};
$http.get("http://lucassmuller.com/work/projetoblog/api.php?action=posts").then(function(data) {
factory.chats = data;
console.log('data ok');
});
return factory;
});
controllers.js
angular.module('starter.controllers', [])
.controller('DashCtrl', function($scope) {})
.controller('ChatsCtrl', function($scope, Chats) {
// With the new view caching in Ionic, Controllers are only called
// when they are recreated or on app start, instead of every page change.
// To listen for when this page is active (for example, to refresh data),
// listen for the $ionicView.enter event:
//
//$scope.$on('$ionicView.enter', function(e) {
//});
$scope.chats = Chats.all();
})
.controller('ChatDetailCtrl', function($scope, $stateParams, Chats) {
$scope.chat = Chats.get($stateParams.chatId);
})
.controller('AccountCtrl', function($scope) {
$scope.settings = {
enableFriends: true
};
});
しかし、私は実行します。$http.get not working at .factoryで私によって作られた問題の回答に基づいて、私は次のコードを書きましたそれはデータでng-repeatを実行するために、チャットが定義されていないというエラーを表示します。どうすれば修正できますか?
依存モジュールとして 'starter.services'を' starter.controllers'に注入する必要があるかもしれません。 – Iceman
controller.jsファイルで 'angular.module( 'starter.controllers'、['starter.services '])'を実行してください – Iceman
しかし、app.jsで接続されています: 'angular.module( 'starter'、[ –