1

Controller.js file code:

var myApp=angular.module('myApp',[]);

myApp.controller('myController', function($scope,$http){

    $http.get('data.json').success(function(data){
        $scope.art=data;
    }); 
});
1
  • $scope.art=data; replace data with response Commented Jul 25, 2017 at 11:50

2 Answers 2

2

You have to assign response to $scope.art

var myApp=angular.module('myApp',[]);

myApp.controller('myController', function($scope,$http){

    $http.get('data.json').success(function(response){
        $scope.art=response;
    }); 
});

Note : The deprecated .success and .error methods have been removed from AngularJS 1.6

Using .then

var myApp=angular.module('myApp',[]);

myApp.controller('myController', function($scope,$http){

    $http.get('data.json').then(function(response){
        $scope.art=response.data;
    }); 
});
Sign up to request clarification or add additional context in comments.

3 Comments

What is your angular version and what does your response contain?
It is showing following error: TypeError: $http.get(...).success is not a function
It is because you are using newer version of angularjs where .success and .error methods have been deprecated. Instead use .then
2
var myApp=angular.module('myApp',[]);

myApp.controller('myController', function($scope,$http){

    $http.get('data.json').then(function(response){
        $scope.art=response.data;
    }); 
});

Try with above. Might help!!

1 Comment

My pleasure I have been helpful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.