The template I am working with looks like this:
<div class="book-thumbs">
<div class="book-pic" ng-repeat="img in book.images">
<img ng-src="{{img}}" ng-click="vm.setImage(img)">
</div>
</div>
When trying to invoke setImage() in the controller, an error is thrown: $scope is not defined.
class BookController {
constructor($scope, $stateParams, $http) {
this.name = 'book';
$scope.bookId = $stateParams.bookId;
this.getBookInfo($http, $stateParams, $scope);
}
getBookInfo($http, $stateParams, $scope) {
$http.get('books/' + $stateParams.bookId + '.json').success(function(data) {
$scope.book = data;
$scope.mainImageUrl = data.images[0];
});
}
setImage(imageUrl) {
$scope.mainImageUrl = imageUrl;
}
}
BookController.$inject = ['$scope', '$stateParams', '$http'];
export default BookController;
To resolve this issue, I tried adding $scope as a parameter in setImage($scope, img), but it did not work. Any suggestions on how to fix this would be greatly appreciated. Thank you!