I am facing an issue with the structure of my controller. Here is how it currently looks:
MyControllers.controller('ContentCtrl', ['$scope', '$http', '$routeParams', function($scope, $http, $routeParams) {
$http.get('js/data.json').success(function(data){
$scope.meta = data;
$scope.whichItem = $routeParams.itemName;
console.log($scope.whichItem);
}).error(function() {
alert('Unable to retrieve information :-(');
});
$scope.title1 = [{"title":"Redhat Theme Guide"}];
$scope.title2 = [{"title":"Debian Theme Guide"}];
}]);
There is also a JSON array included in the code:
[
{
"category":"category1",
"link":"category1",
"expand":false,
"keyword":"category1, category1 online, category1 something"
},
{
"category":"category2",
"link":"category2",
"expand":false,
"keyword":"category2, category2 online, category2 something"
}
]
The problem arises when trying to access data from the array using {{meta[whichItem].keyword}}
. The issue lies in the fact that the whichItem
variable is always interpreted as a string rather than an integer, which is necessary for accessing the array index properly. I attempted to use parseInt()
along with slice()
, but so far have not been successful in resolving this issue.