Below is the code for my controller:
$scope.mainModel = getReviews({model: mainModelArr[1]});
$scope.compareModel = getReviews({model: compareModelArr[1]});
function getReviews(data) {
$http.post(url, data)
.success(function(res) {
formatReviews(res);
})
.error(function(err) {
console.log("An error occurred: " + err);
});
}
function formatReviews(data) {
var review = data[0];
review.sumReviews = (review.sumReviews / review.ratingAvg).toFixed(0);
review.sumRecommend = (review.sumRecommend / review.sumReviews * 100).toFixed(1);
review.ratingAvg = review.ratingAvg.toFixed(1);
console.log(review); // logs message correctly
return review;
}
Even though these functions are running without errors and logging the review variable, it seems like the review
variable is not being assigned to either $scope.mainModel
or $scope.compareModel
.
NOTE: I am aware that it was not assigned because it does not appear in the HTML:
<p>{{mainModel}}</p>
What mistake did I make and how can I correct it?