I have an Angular function within a PHP partial page that appears to not be working properly. The function is attached to all images that are loaded on to the page from a MySQL database, and is called with ng-click="vm.openModal('custom-modal-1')"
.
<div id="screenings">
<?php
...
//connect to MySQL database
...
while ($row = mysqli_fetch_array($result)){
echo "<div class='img_div'>";?>
//here is the ng-click that calls the Angular function
<img class="modal_img img_screenings" ng-click="vm.openModal('custom-modal-1')" src='images/<?php echo $row['image']."' >";
...
echo "</div>";
}
?>
</div>
//here is the modal with the id that gets passed to the Angular function
<modal id="custom-modal-1">
<div class="modal">
<div class="modal-body">
<img id="popup_img" src="#">
</div>
</div>
<div class="modal-background"></div>
</modal>
Within the file app.js, here is the function that I'm trying to call:
app.controller('screeningsController', ['$scope', '$log', "ModalService", function($scope, $log, ModalService){
var vm = this;
//outputs "Hello World!" to browser console as a test
vm.message = "Hello World!";
$log.log(vm.message);
vm.openModal = openModal;
vm.closeModal = closeModal;
function openModal(id){
ModalService.Open(id);
}
function closeModal(id){
ModalService.Close(id);
}
}]);
When the partial page is loaded in, the test message "Hello World!" that is found within the Angular function fires, and the message appears in the browser console. However, the ng-click
doesn't do anything else when any img
with class modal_img
is clicked on the page.
All Angular modal window materials for this code was taken from: http://jasonwatmore.com/post/2016/07/13/angularjs-custom-modal-example-tutorial
EDIT Controller as
is declared at the top of the app.js file, like so:
var app = angular.module('app', ['ngRoute', 'ui.router']);
app.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
$locationProvider.hashPrefix('');
$urlRouterProvider.otherwise("/");
$stateProvider
.state('home', {
url: '/',
templateUrl: 'pages/main.html',
controller: 'mainController',
controllerAs: 'vm'
})
.state('screenings', {
url: '/screenings',
templateUrl: 'pages/screenings.php',
controller: 'screeningsController',
controllerAs: 'vm'
})
//etc