phpmysqlangularjsangularjs-ng-clickng-controller

ng-click function called within php echo statement not working


I'm trying to implement an ng-click on images that are pulled from a MySQL database, but I can't seem to get a test log message to appear in the console.

Here is a section from a partial where the ng-click is. The ng-click is in the first echo statement:

<div id="screenings" ng-controller="screeningsController">
        <?php
            $db = mysqli_connect("localhost", "root", "", "database");
            $sql = "SELECT * FROM screenings ORDER BY id DESC";
            $result = mysqli_query($db, $sql);
            while ($row = mysqli_fetch_array($result)){
                echo "<div id='img_div' ng-click='popup()'>";
                    echo "<img id='img_screenings' class='modal_img' src='images/".$row['image']."' >";
                    echo "<p id='movie_p' align='center'>" .$row['movie']."</p>";
                    echo "<p id='screenings_p' align='center'>" .$row['venue']."</p>";
                    echo "<p id='location_p' align='center'>" .$row['location']."</p>";
                    echo "<p id='date_p' align='center'>".date('F j, Y',strtotime($row['date']))."</p>";
                echo "</div>";
            }
        ?>
    </div>

Here is the code for the ng-controller within app.js. I'm trying to get a simple log message to appear in the console, but I'm not seeing it:

myApp.controller('screeningsController', ['$scope', '$log', function($scope, $log){

$scope.popup = function(){
    $scope.$log = $log;
    $scope.message = 'Hello World!';
};

}]);

Solution

  • Well it seems like you are actually not logging out anything. You are just assigning the $log service to $scope. Try changing your popup function to the following:

    $scope.popup = function () {
    
        // assign a message to the $scope
        $scope.message = 'Hello World!';
    
        // use the $log service to output the message in a console
        $log.log($scope.message);
    
    };