madson gr madson gr - 3 months ago 15
Javascript Question

AngularJS + ion-list ng-repeat not Populating List

I am trying to populate an ion-list with ng-repeat from the database in Intel XDK using AngularJS and PHP.

I made some tries after reading some questions but nothing has worked. It populates an empty list or nothing is displayed. What´s wrong with my code?

HTML:

<ion-view title="Temporada 2016" id="page1" style="background-color:#FFFFFF;">
<ion-content padding="true" class="has-header">
<div id="temporada2016-button-bar1" class="button-bar">
<button id="temporada2016-button2" style="color:#008BBB;" class="button button-light button-block button-outline active-bymyself">Notícias</button>
<a ui-sref="menu.fotos" id="temporada2016-button3" style="color:#008BBB;" class="button button-light button-block button-outline">Fotos</a>
</div>
<form id="temporada2016-form8" class="list">
<label class="item item-input" name="search_news">
<i class="icon ion-search placeholder-icon"></i>
<input type="search" placeholder="Pesquisar Notícia">
</label>
</form>
<!--<div class="item item-body list-container" id="temporada2016-list-item-container4">
<div id="temporada2016-markdown7" style="margin-top:0px;color:#666666;">
<p>{{title}}</p>
</div>
</div> -->
<ion-list class="widget uib_w_1 d-margins" data-uib="ionic/list" data-ver="0">
<ion-item class="item widget uib_w_2" data-uib="ionic/list_item" data-ver="0" ng-repeat="x in items">{{ x.TITLE }}</ion-item>
</ion-list>
</ion-content>
</ion-view>


Angular:

.controller('temporada2016Ctrl', ['$scope', '$http', function ($scope, $http) {

$http.get("http://localhost/select-news.php").then(function(response){

console.log(response);
console.log(JSON.stringify(response));

$scope.items = response.data.records;

});

}])


PHP

<?php

include_once('conn.php');

$sql = $mysqli->query("SELECT * FROM news");

if($sql->num_rows > 0){
while($row = $sql->fetch_array(MYSQLI_BOTH)){
$registro = array(
"ID" => $row['id'],
"TITLE" => $row['title'],
"BODY" => $row['body']
);

$retorno[] = $registro;

}
}

$mysqli->close();
$retorno = json_encode($retorno);
echo $retorno;

?>


UPDATE
JSON

[{"ID":"0","TITLE":"Events of the Day","BODY":"Main Party at 22h!"}]

Answer

try to change

$scope.items = response.data.records;

to

$scope.items = response.data;

Or show your JSON here