I am making a call to my backend, which returns a list of objects as JSON. Now, I want to iterate these in the frontend in my Angular app.
However, when the HTML i wrote below is rendered, nothing is shown. I have no idea why, as I was sure this was the syntax.
There are no JavaScript errors in the console. Also, I was unsure if it was the $scope inside an async call that caused my problem, but it seems that if I copy the response from the API out and puts it as a string (therefore sync and not async), nothing is shown still.
Any idea where my bug is? (Disclaimer: as I am new to Angular, I might have made a newbie mistake!)
My angular app:
var app = angular.module("app", ['ngRoute'])
app.config(function($routeProvider) {
$routeProvider.when('/front', {
templateUrl: '/templates/front.html',
controller: 'FrontController'
});
$routeProvider.otherwise({redirectTo: '/front'})
});
app.controller('FrontController',['$scope',function($scope) {
$.ajax({
type: 'GET',
url: '/api/serials',
dataType: 'json',
success: function(data){
$scope.serials = data;
},
error: function(err) {
alert('fejl');
}
});
$scope.datatitle = 'hheeh';
}]);
The AJAX call:
In my network category, I can see the following are returned from the API:
[{"_id":"53cf8b80a20055c6eebf80b1","serial":"1231323123","game":"World of Warcraft","date":"2013-12-31T23:00:00.000Z"}]
My HTML:
The HTML rendered in the frontend is: "Angular works: 8"
My code is:
Angular works: {{ 4+4 }}
{{serial.length}}
<ul>
<li data-ng-repeat="serial in serials">{{serial}}</li>
</ul>
EDIT:
Console log of data:
