HELP!お願いします。 SQL、PHP、およびJSONを使用してデータベースを作成するのは初めてです。AngularJS、MySQL、PHP、JSON - データベースからデータが表示されない
私のデータは、XAMPPを使用してデータベース(ローカルホスト)から表示されません。 MySQLからデータをフェッチするためのPhp行を作成してから、AngularJSが処理できるようにJSONファイルを作成します。しかし、私のデータは全く表示されません。
Devツール(Chrome)にはエラーは表示されません。コードまたは作成したデータベースに問題はありますか?ここで
は、これは私のapp.jsである私のapi.php
<?php
$db_name = 'talents';
$hostname = 'localhost';
$username = 'root';
$password = '';
$dbh = new PDO("mysql:host=$hostname;dbname=$db_name", $username, $password);
$sql = 'SELECT id, name, images, images2, images3, indexing FROM talents';
$stmt = $dbh->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
$json = json_encode($result);
echo $json;
?>
ある
(function() {
var alice = angular
.module('alice', [])
.controller('AliceController', function ($scope, $http) {
$http.get('api.php').
then(function (talents) {
$scope.talents = talents;
});
});
})();
最終は私のHTML
<div ng-controller="AliceController" class="talent-container">
<div ng-repeat="talent in talents" class="card boxed" ng-class=" {{talent.indexing}}">
<div class="actionlist">
<div id="id"><span>{{talent.id}}</span></div>
<div class="addBtn">
<a href="#"><img src="assets/icons/plus.svg"></a>
</div>
<div class="loveBtn">
<a href="#"><img src="assets/icons/heart-in-a-circle.svg"></a>
</div>
</div>
<div class="media">
<div><img id="slideShow" ng-src="{{talent.images}}"></div>
<div class="hide"><img id="slideShow" ng-src="{{talent.images2}}"></div>
<div class="hide"><img id="slideShow" ng-src="{{talent.images3}}"></div>
</div>
<div class="info">
<div id="name">{{talent.name}}</div>
<div class="button medium">
<a href="detail.html" class="moreBtn">MORE</a>
</div>
</div>
<div class="skills-thumb">
<a ng-repeat="skill in talent.skills" href="#" class="boxedMedium">{{skill.name}}</a>
</div>
</div>
</div>
を提供することができサーバーまたはクライアントのどこに問題があるのかを判断してください。 –
あなたのjsにはあなたが持っているものがあります... $ scope.talents = talents; ...あなたの才能変数はあなたのHTMLにおいて単数ですが、それは正常ですか?あなたのHTMLコードの回りにngForループをしますか? – mickaelw
あなたのhttpコールがエラーコールバックを許可する範囲: '$ http.get( 'api.php')then((res)=> {$ scope.talents = res.data;}、(err)=> {console。 –