0

So i'm testing $http.get in angular to grab a json file and i've used this code:

$scope.classes =   $http.get('coursedata.json')
    .success(function (result){
           $scope.classes = result; a
      console.log(result);
             })
  .error(function(data,status){
  console.log(status);
  } );

but it wasn't working, its showing a successful get but in my angular html page it is not accessing the data.

my html is something like:

<div class="row" ng-controller="oflClassCtrl">
 <tr ng-repeat = "selectedClass in classes | filter:searchTxt">
        <td><a  ng-click="clickToOpen($index)">{{selectedClass.class}}</a></td>

the page renders correctly when i have the data in the controller but for some reason something is not working when i try to use the get request and $http service.

also im running a local host with php on xampp apache server so the $http should work right?

3
  • 1
    what errors do you get? Is the json valid? If in doubt run it through a validator Commented Jan 14, 2015 at 23:34
  • what if you type the http address of your JSON file in your browser. what do you see? Commented Jan 14, 2015 at 23:34
  • the json was not correct and was missing commas. please create an answer for this so i can accept it. Commented Jan 15, 2015 at 18:25

3 Answers 3

1

$scope.classes likely has invalid assigned to it, hence the successful $http.get but dysfunctional ng-repeat in your markup. Examining your JSON format should fix the issue

JSONLint - one of the many quick online tools you can use

Sign up to request clarification or add additional context in comments.

Comments

0

try producing a function at your scope, and set data there:

$scope.setData = function( data ) {
....

I think this is something with watch context.

Comments

0

There's no function in the scope variable:

$scope.classes =  function() {
$http.get('coursedata.json')
    .success(function (result){
           $scope.classes = result; a
      console.log(result);
             })
  .error(function(data,status){
  console.log(status);
  } );
}

Considering you want to call it or the function to be triggered

Comments

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.