Answer the question
In order to leave comments, you need to log in
Angular.js - Is it possible to take data from a json file by url?
I recently started learning angular and, like many others, I started with a tutorial on angular.ru. The tutorial explains step by step how to display a list of phones with a description in html from a json file. (PhonecatApp).
var phonecatApp = angular.module('phonecatApp', []);
phonecatApp.controller('PhoneListCtrl', function ($scope, $http) {
$http.get('phones/phones.json').success(function(data) {
$scope.phones = data;
});
$scope.orderProp = 'age';
});
var phonecatApp = angular.module('phonecatApp', []);
phonecatApp.controller('PhoneListCtrl', function ($scope, $http) {
$http.get('https://secret-coast-8851.herokuapp.com/phones.json ').success(function(data) {
$scope.phones = data;
});
$scope.orderProp = 'age';
});
Answer the question
In order to leave comments, you need to log in
As already mentioned, you need to use jsonp. And do not forget about JSON_CALLBACK
In my application it is used like this:
$http.jsonp(url+'&callback=JSON_CALLBACK') # url = Ваш url
.success(data)->
#some code
.error(data) ->
#some code
If the backend is yours and the domain is different from what the client is taken from, use jsonp . Angular works great with it.
Either start the static server from localhost, or start the browser (chrome) with --disable-web-security
Remove the space at the end of the address ' https://secret-coast-8851.herokuapp.com/phones.json '
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question