i have a problem that i don’t know how to solve, i have an IONIC Tabs Template and want to add an external JSON File
This is my app.js file:
.state('tab.chats', {
url: '/chats',
views: {
'tab-friends': {
templateUrl: 'templates/tab-chats.html',
controller: 'ChatsCtrl'
}
}
})
.state('tab.chats-detail', {
url: '/chats/:chatsid',
views: {
'tab-friends': {
templateUrl: 'templates/chats-detail.html',
controller: 'ChatsDetailCtrl'
}
}
})
This is my controllers.js file
.controller('ChatsCtrl', function($scope, Chats) {
$scope.friends = Chats.all();
})
.controller('ChatsDetailCtrl', function($scope, $stateParams, Chats) {
$scope.friend = Chats.get($stateParams.chatsid);
})
This is my services.js file, that access a JSON file:
.factory('Chats', function($http) {
var chats = [];
return {
all: function(){
return $http.get("http://ataquepropaganda.com.br/equipos.json").then(function(response){
chats = response.data;
console.log(chats );
return chats ;
});
},
get: function(chatsid) {
for (var i = 0; i < chats.length; i++) {
if (chats[i].id === parseInt(chatsid)) {
return chats[i];
}
}
return null;
}
}
});
And finally my tabs-chats.html template:
<ion-view view-title="Chats">
<ion-content>
<ion-list>
<ion-item class="item-remove-animate item-avatar item-icon-right" ng-repeat="chat in chats" type="item-text-wrap" href="#/tab/chats/{{chats.id}}">
<!--img ng-src="{{chat.face}}"-->
<h2>{{chats.name}}</h2>
<p>{{chats.bio}}</p>
</ion-item>
</ion-list>
</ion-content>
</ion-view>