我正在尝试对从MySQL数据库中提取的图像实施ng-click,但我似乎无法在控制台中显示测试日志消息。
以下是ng-click所在部分的部分。 ng-click位于第一个echo语句中:
<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>
以下是app.js中ng-controller的代码。我试图在控制台中显示一条简单的日志消息,但我没有看到它:
myApp.controller('screeningsController', ['$scope', '$log', function($scope, $log){
$scope.popup = function(){
$scope.$log = $log;
$scope.message = 'Hello World!';
};
}]);
答案 0 :(得分:1)
好吧,你好像没有注销任何东西。您只是将$log
服务分配给$scope
。尝试将popup
功能更改为以下内容:
$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);
};