I am trying to have a variable string, and access the matching $scope.field but it is undefined and not returning what I am expecting. What am I doing wrong, or is this not possible?
$scope.selectedHolidayA = "Christmas"
$scope.selectedHolidayB = "NewYears"
var HA = "selectedHolidayA";
var HB = "selectedHolidayB";
I want to get the same result as $scope.selectedHolidayA = "Christmas". But I am getting undefined.
I tried these but no luck.
console.log("Test 1", $scope["HA"]); //I want these to return "Christmas"
console.log("Test 2", $scope[HA]); //Currently returns undefined
console.log("Test 3", $scope.HA);
Is it possible to pass variables, if so how? Thanks!