Hi Iconic members,
I’m trying to receive data from a web host in a json file into my application. I’ve successfully was able to load one message into my application but it just kept repeating itself. I have adjusted my code to $scope.newposts but i’m having no luck and it’s now not even receiving any json data. Could somebody could have a quick look? Thank you.
My HTML:
<ion-view view-title="Announcements">
<ion-content ng-controller="Controller">
<ion-refresher on-refresh="doRefresh()">
</ion-refresher>
<ion-list>
<ion-item ng-repeat="item in items" ng-click="getData()">
<div class="list card">
<div class="item item-divider">{{item.announcement_name}} - {{item.date}}</div>
<div class="item item-body">
<div>
{{item.message}}
</div>
</ion-item>
</ion-list>
</ion-content>
</ion-view>
My Javascript:
angular.module('ionicApp', ['ionic', 'ngResource'])
.factory('Post', function($resource) {
return $resource('/api/post/:id');
})
.controller('Controller', function($scope, $http, Post) {
$scope.items = [1,2,3];
$scope.doRefresh = function() {
$http.get("")
.success(function(data) {
$scope.posts = data.announcement_name;
$scope.posts = data.date;
$scope.posts = data.message;
})
.finally(function() {
// Stop the ion-refresher from spinning
$scope.$broadcast('scroll.refreshComplete');
});
};
// Our form data for creating a new post with ng-model
$scope.postData = {};
$scope.newPost = function() {
var post = new Post($scope.postData);
post.$save();
}
});