Currently, I am developing a website using AngularJS that retrieves questions and multiple-choice answers from an Amazon Web Services table. This data is used to dynamically create a prelab questions page. The http get request is functioning properly; when I check the value of data.data at breakpoints, it contains all the necessary information.
However, once I assign this data to $scope.allQuestions, the variable appears as undefined in the console. The same issue occurs with $scope.allAnswers. Interestingly, I have successfully used similar code to fetch thumbnail/simulation URLs on another page without any problems.
The $location functionality is working as expected, and I have also implemented $filter for later use in filtering within an ng-repeat.
I make use of AWS API Gateway to make these calls. CORS is enabled, and the settings for these two functions are identical to those used in the function that is functioning correctly.
Below is the code snippet. Thank you in advance!
app.service('preLabService', function($http) {
this.getQuestions = function() {
return $http.get('api-gateway-url');
};
this.getAnswers = function() {
return $http.get('api-gateway-url');
};
});
app.controller('PreLabQuestionsCtrl', ['$scope', '$location', '$filter', 'preLabService', function($scope, $location, $filter, preLabService) {
init();
function init() {
preLabService.getQuestions().then(function(data) {
$scope.allQuestions = data.data;
});
preLabService.getAnswers().then(function(data) {
$scope.allAnswers = data.data;
});
$scope.simURL = $location.search().simURL;
$scope.simID = $location.search().SimID;
}
}]);
In my actual browser code, I replace *'api-gateway-url' with the respective URLs - for security reasons, I chose not to disclose the specific API URL here.