hello,
i am trying to read from a json file on a server.i tried.i got some errors.including uncaught syntaxerror unexpected.i followed a tutorial :http://samcroft.co.uk/2016/loading-json-into-an-ionic-app/.i used another service and used get insted of jsonp.i added callback=JSON_CALLBACK to the link but nothing.no errors.no console log.here’s my code
`
angular.module(‘app.services’, [])
.factory(‘Articles’, function($http,$q) {
var url = ‘https://www.yabiladi.com/newsapi.json?callback=JSON_CALLBACK’;
//allarticles
return {
getArticles: function() {
return $http.jsonp(url);
},
//articlebyid
getArticle: function(articleId) {
return $http.jsonp(url, {
params: {
id: articleId
}
});
}
}
})
.service('servicearticles',function($http,$q)
{
var deferred=$q.defer();
$http.get('https://www.yabiladi.com/newsapi.json?callback=JSON_CALLBACK').then(function(response)
{
deferred.resolve(response);
});
this.getArticles=function()
{
return deferred.promise;
}
})
angular.module(‘app.controllers’, [])
.controller(‘articlesController’, function(servicearticles, $scope) {
servicearticles.getArticles().then(function(response){
$scope.articles = response.data;
console.log(articles);
}).catch(function(response){
//request was not successful
//handle the error
});
})
.controller('articleDetailController', function(Articles, $stateParams, $scope) {
Articles.getArticle($stateParams.articleId).then(function(response){
$scope.article = response.data;
}).catch(function(response){
//request was not successful
//handle the error
});
});
`
ion-view title="Articles" id="page1"> <ion-content padding="true" class="has-header"> <ion-list> <ion-item ng-repeat="article in articles.articles" ng-href="#/articles/{{article.id}}"> {{article.titre}} </ion-item> </ion-list> </ion-content> </ion-view>
`
$stateProvider
.state('articles', {
url: '/page1',
templateUrl: 'templates/articles.html',
controller: 'articlesController',
controllerAs: 'articles'
})
.state(‘details’,{
url:’/page2/:articleid’,
templateUrl:‘templates/details_article.html’,
controller :‘ArticleDetailController’,
controllerAs: ‘articleDetail’
})
$urlRouterProvider.otherwise(’/page1’)
});`
thank for your help