Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to use JSONP in AngularJS resource
    primarykey
    data
    text
    <p>I'm trying to import json object into variable. I use the services according to tutorial. </p> <p>I receive unexpected token error, because i shouldn't use <code>$scope.news = JsonSource.feed();</code> - but I really don't know what should I use. I googled and searched 3 hours I find only $http. or $json. answers, but I feel, that it could be done easier - clearer. </p> <p>(The perfect solution would be <code>$scope.news = JsonSource.feed().entries</code> ;D</p> <p>The services file:</p> <pre><code>var AAAServices = angular.module('AAAServices', [ 'ngResource' ]); AAAServices.factory('JsonSource', ['$resource', function($resource) { return $resource('https://www.facebook.com/feeds/page.php', {}, { feed: {method:'JSONP', {format: 'json', id:'459908', callback : JSON_CALLBACK}, isArray:false} }); }]); </code></pre> <p>The controllers file:</p> <pre><code>var AAAControllers = angular.module('AAAControllers', []) AAAControllers.controller('newsCtrl', ['$scope', 'JsonSource', function newsCtrl($scope, JsonSource) { $scope.news = JsonSource.feed(); }]); </code></pre> <p>the json file (almost ;D)</p> <pre><code>{ "title": "Tytuł", "link": "https:\/\/www.facebook.com\/", "entries": [ { "title": " news 1", "id": "1" }, { "title": " news 2", "id": "2" } ] } </code></pre> <p><strong>Edited:</strong></p> <p>i change $resource('file.json into <a href="https://www.facebook.com/feeds/page.php" rel="noreferrer">https://www.facebook.com/feeds/page.php</a> - so you can check if it is json or jsonp...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload