Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Ryan Hellerud
Ryan Hellerud
3,635 Points

using angular $http service

So im trying to access a json file in angular using the $http service but struggling to set it up as im new to angular and still don't really understand it well. Now, I am able to hack together some code and using ng-repeat to set up some basic functionality. ALso, I tried going through the angular tutorial here but it doesn't seem to make much sense. Can anyone give me a reference or a way to set up a way to return a json file so that it can be used for ng-repeat. Im trying something like:

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

oflApp.controller('oflClassCtrl', function ($scope, $http) {

  $scope.classes = $http.get('../courses/coursedata.json')
   <label>Filter:</label>
      <input type="text" ng-model="searchTxt" placeholder="Enter a class here">
      <hr></div>
      </div>

<!--      <h1>Test {{searchTxt}}!</h1>-->
    </div>
 <table ng-controller="oflClassCtrl">
  <thead>
    <tr>
      <th>Course Title(Apex/Isis)</th>
    </tr>
  </thead>
  <tbody>
    <tr ng-repeat = "selectedClass in classes | filter:searchTxt">
        <td><a href="#" data-reveal-id="myModal" ng-click="setClass($index)">{{selectedClass.class}}</a></td>

    </tr>

its giving me: XHR finished loading: GET "http://localhost/courses/coursedata.json". angular.js:11592 SyntaxError: Unexpected token {