I am trying to read a file in angular js where if the data is read successfully it will assign the content to a variable of an object else it will assign "NA" to that same variable.
function customer($scope, $http) {
var i;
$scope.courses = [{
name: "CSE",
capacity: "CSE.txt"
}, {
name: "IT",
capacity: "IT.txt"
}, {
name: "ECE",
capacity: "ECE.txt"
}];
for (i = 0; i < 3; i++)
$http.get($scope.courses[i].capacity).then(function (success) {
$scope.courses[i].capacity = success.data;
}, function (error) {
$scope.courses[i].capacity = "NA";
});
}
var myApp = angular.module("myApp", []);
myApp.controller("customerobj", customer);
I try to access the following part in a normal table format
<td>ng-repeat="course in courses">{{course.capacity}}</td>
But every time I do that it's throwing an error: "Cannot set property 'capacity' of undefined" and showing the file names. Even though if the files are not found it is supposed to update the value to "NA". But it is not happening. Please help me out