您好我是JSON和Angular的新手,我一直在努力向我的框架显示我的数据。只有空白页但没有错误
这是我的控制器
.controller('PetIndexCtrl', function($scope, PetService) {
$scope.pets = PetService.all();
console.log($scope.pets);
})
这是我的工厂
.factory('PetService', function($http, $ionicPlatform) {
var markers = [];
return {
all: function(){
return $http.get("https://192.168.1.10/getEvent.php").then(function(response){
markers = response;
return markers;
});
}
}
});
这是我的离子框架
<scrip id="pet-index.html" type="text/ng-template">
<ion-view title="'Rooms'">
<ion-content has-header="true" has-tabs="true">
<ion-list>
<ion-item ng-repeat="pet in pets" type="item-text-wrap" href="#/tab/pet/{{pet.id}}">
<h3>{{ pet.prof }}</h3>
</ion-item>
</ion-list>
</ion-content>
</ion-view>
</script>
这是我的php
$mysqli = new mysqli("localhost", "root", "", "info");
$result = "{'success':false}";
$query = "SELECT * FROM viewsched";
$dbresult = $mysqli->query($query);
$markers = array();
while($row = $dbresult->fetch_array(MYSQLI_ASSOC)){
$markers[] = array(
'prof' => $row['Professor'],
'sub' => $row['Subject'],
'time' => $row['Time'],
'room' => $row['Room'],
'day' => $row['Day']
);
}
if($dbresult){
$result = json_encode($markers);
}
else
{
}
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type,x-prototype-version,x- requested-with');
echo($result);
我已尝试过所有内容,但仍然没有显示任何数据。有人能帮我吗。感谢
答案 0 :(得分:0)
这引起了我的注意
<scrip id="pet-index.html" type="text/ng-template">
应该是
**<script id="pet-index.html" type="text/ng-template">**
答案 1 :(得分:0)
$ http.get函数返回一个promise。你称它为'then'函数,它也会返回一个承诺,而不是你的数据。
而不是
$scope.pets = PetService.all();
console.log($scope.pets);
试
var promise = PetService.all();
promise.then(function(response){
var markers = response;
console.log(markers);
});