Reputation: 1628
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?
Upvotes: 0
Views: 1699
Reputation: 16989
$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
Upvotes: 1
Reputation: 97
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
Upvotes: 0
Reputation: 575
try producing a function at your scope, and set data there:
$scope.setData = function( data ) {
....
I think this is something with watch context.
Upvotes: 0