gpt4 book ai didi

php - angularjs $scope不在html View 中显示数据,但数据显示在控制台中

转载 作者:行者123 更新时间:2023-11-29 10:16:52 25 4
gpt4 key购买 nike

我正在尝试将数据从数据库读取到 Web 浏览器中应用程序的 View 中。问题是我无法显示任何数据。数据显示在控制台中,因此它正在连接到数据库,但不知何故它不会在 View 中打印数据。

Data is showing in console but not in view

playerDetails.php

include 'database_connections.php';

$sql = "SELECT idPlayer, PlayerName, PlayerEmail, PlayerPassword,
PlayerTeam FROM Players";
$result = mysqli_query($conn, $sql);

$data = array();
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$data[] = $row;
}
} else {
echo "0 results";
}

mysqli_close($conn);
echo json_encode($data);

angular-script.js( Controller )

var crudApp = angular.module('crudApp',[]);

crudApp.controller('DbController', function ($scope, $http) {
$http.get("DatabaseFiles/playerDetails.php")
.then(function (response) {$scope.players = response.data;
console.log(response.data)
});
});

HTML

<!doctype html>
<html ng-app='crudApp'>
<head>
<title>Crud app</title>

<script src="js/jQuery/jquery.min.js"></script>
<script src="lib/angular/angular.min.js"></script>

</head>

<body>
<div ng-controller="DbController">

<table >
<tr>
<th>Player ID</th>
<th>Name</th>
<th>Email</th>
<th>Password</th>
<th>Team</th>
</tr>

<tr ng-repeat="players in Players | orderBy:'-created'">
<td>{{players.idPlayer}}</td>
<td>{{players.PlayerName}}</td>
<td>{{players.PlayerEmail}}</td>
<td>{{players.PlayerPassword}}</td>
<td>{{players.PlayerTeam}}</td>
</tr>

</table>
</div>
<script src="js/angular-script.js"></script>
</body>

已解决

我不确定是什么导致了问题,但我创建了一个新数据库和一个新项目,并对我的 PlayerController.js(以前的“angular-script.js”)和 index.html 进行了以下更改

PlayerController.js

var app = angular.module('crudApp', []);
app.controller('mainController', function($scope, $http) {

$http.get('PlayerRead.php').then(function(response) {
$scope.users = response.data;
console.log(response.data);
});
});

HTML

<!doctype html>
<html >
<head>
<title>Crud app</title>
<script
src="https://ajax.googleapis.com/ajax/libs/
angularjs/1.6.4/angular.min.js"
></script>
</head>

<body ng-app="crudApp" ng-controller="mainController">
<table>
<tr>
<th>Player ID</th>
<th>Name</th>
<th>Email</th>
<th>Team</th>
</tr>

<tr ng-repeat="user in users track by $index">
<td>{{user.PlayerID}}</td>
<td>{{user.PlayerName}}</td>
<td>{{user.PlayerEmail}}</td>
<td>{{user.PlayerTeam}}</td>
</tr>

</table>

<script src="PlayerController.js"></script>
</body>

最佳答案

将其设置为以下行,因为它区分大小写。

    <tr ng-repeat="player in players | orderBy:'-created'">
<td>{{player.idPlayer}}</td>
<td>{{player.PlayerName}}</td>
<td>{{player.PlayerEmail}}</td>
<td>{{player.PlayerPassword}}</td>
<td>{{player.PlayerTeam}}</td>
</tr>

关于php - angularjs $scope不在html View 中显示数据,但数据显示在控制台中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50011736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com