I am reading a json file and displaying in the view.
My JSON FILE
[
{
"DayNum": "1",
"Date": "January 01, 2015",
"Title": "Miracle Rain",
"By": "By Poh Fang Chia",
"Passage": "1 Kings 18:1,41-45",
"Memory": "I am God, and there is no other.Isaiah 46:9",
"Devotion": "Life is hard for the villagers..."
}
]
MY SERVICE
.factory('DevotionService',function($rootScope,$http){
var serviceUrl = 'file:///android_asset/www/';
var Devotion;
return {
getDevotion : function(dayNum){
return $http.get(serviceUrl + 'json/'+dayNum+'.json').then(function(data){
Devotion = data;
return Devotion;
});
}
}
})
My Controller
.controller('ViewDevotionCtrl', function($scope,$localstorage,$location,$ionicHistory,$cordovaDevice,DevotionService,$stateParams){
if($stateParams.dayId==0){
Date.prototype.isLeapYear = function() {
var year = this.getFullYear();
if((year & 3) != 0) return false;
return ((year % 100) != 0 || (year % 400) == 0);
};
// Get Day of Year
Date.prototype.getDOY = function() {
var dayCount = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
var mn = this.getMonth();
var dn = this.getDate();
var dayOfYear = dayCount[mn] + dn;
if(mn > 1 && this.isLeapYear()) dayOfYear++;
return dayOfYear;
};
var today = new Date();
var daynum = today.getDOY();
console.log(daynum);
Devotion = DevotionService.getDevotion(daynum);
**$scope.devotions = Devotion;** - this line causes the app to stop working
}else{
Devotion = DevotionService.getDevotion($stateParams.dayId);
console.log(Devotion[daynum].Title);
}
})
MY TEMPLATE
<ion-view title="View Devotion">
<ion-header-bar class="bar-positive"><h1 class="title">View Devotion</h1></ion-header-bar>
<ion-content>
<ul ng-repeat="dev in devotions">
<li>{{dev.Title}}</li>
</ul>
</ion-content>
</ion-view>