I am in need of loading the content from either food1.json or food2.json, and I am attempting to achieve this within the html template:
<body ng-controller="MainCtrl" ng-init="init('food1')">
Subsequently, in the JavaScript code:
$scope.init = function (name) {
$scope.name = name;
$scope.category = name + ".json";
$scope.foodlist = {};
$http({
method: 'GET',
url: $scope.category,
}).success(function (data, status, headers, config) {
{
$scope.foodlist = data;
}
}).error(function (data, status, headers, config) {
// something went wrong :(
});
};
});
The category name is correctly concatenated: By printing I am {{ category }}
, I receive "I am food1". However, no food items are being displayed. It appears that there might be an issue with my JSON call.