Hi guys,
I’m trying to get my HTTP.get to work on my pull to refresh. It’s having trouble receiving items from the url. I’ll place all my code related to my HTTP below. If anyone could help me out i would be very grateful. Thanks.
Code:
Tab-accouncements.html:
<html ng-app="ionicApp">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>Ionic Pull to Refresh</title>
<link href="http//code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
<script src="http//code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
<script src="js/controllers.js"></script>
</head>
<body ng-controller="MyCtrl">
<ion-header-bar class="bar-positive">
<h1 class="title">Pull To Refresh</h1>
</ion-header-bar>
<ion-view view-title="Announcements">
<ion-content>
<ion-refresher on-refresh="doRefresh()">
</ion-refresher>
<ion-list>
<ion-item ng-repeat="item in items">{{announcement_name}} {{date}} {{message}}</ion-item>
</ion-list>
</ion-content>
</ion-view>
</body>
</html>
controller.js:
angular.module('myApp', ['ionic'])
.controller('MyCtrl', function($scope, $http) {
$scope.items = [1,2,3];
$scope.doRefresh = function() {
$http.get('http://www.wikicode.co.uk/announcement')
.success(function(newItems) {
$scope.announcement_name = newItems.announcement_name;
$scope.date = newItems.date;
$scope.message = newItems.message;
})
.finally(function() {
// Stop the ion-refresher from spinning
$scope.$broadcast('scroll.refreshComplete');
});
myApp.error(function(newItems) {
alert("something went wrong");
})
};
});
Link:
http://www.wikicode.co.uk/announcement
{
"announcement_name": "Testing"
"date": "16/05/2015"
"message": "Test"
}