Answer the question
In order to leave comments, you need to log in
$http and getting data from json?
Good afternoon, I started reading the angular.ru tutorial, making an example from the tutorial, everything works, I decided to change a little and ran into such a problem, there is a file:
main.json
[
{
"main_view" : 10000,
"main_view_one" : 20000,
"main_view_two" : 30000
}
]
angular
.module('app',[])
.controller('MainList', MainList);
function MainList ($scope, $http) {
$http.get('main.json').success(function(mydata){
console.log(mydata);
$scope.main = mydata;
});
}
<p>{{main_view}}</p>
Answer the question
In order to leave comments, you need to log in
thanks to everyone for the tips, I figured it out, it was necessary to parse json
, it turned out like this:
$scope.result = angular.fromJson(mydata);
$scope.main_view = $scope.result[0].main_view;
In general, it's better to use then, because success has been deprecated.
Because what you received in response to ajax lies in this $scope.main variable. That is, in the template you need to do this - {{main}}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question