这里实际上是完整的错误: 错误:[ngRepeat:dupes]不允许在转发器中重复。使用'跟踪'表达式以指定唯一键。中继器:红毛猩猩,重复键:字符串:",重复值:"
这是我的HTML代码:
<ion-view view-title="Daftar Orang">
<ion-content>
<ion-list>
<ion-item ng-repeat="orang in orangs">
{{orang.nama}}
</ion-item>
</ion-list>
</ion-content>
</ion-view>
这是我的角度控制器:
.controller('OrangCtrl', function($scope, $http, $ionicLoading, $ionicHistory) {
$ionicHistory.nextViewOptions({
disableBack: true
});
//loading
$scope.show = function() {
$ionicLoading.show({
template: '<ion-spinner icon="android"></ion-spinner><br>Harap Tunggu'
}).then(function(){
console.log("The loading indicator is now displayed");
});
};
$scope.hide = function(){
$ionicLoading.hide().then(function(){
console.log("The loading indicator is now hidden");
});
};
$scope.show();
$http({
url: "http://localhost/android_server/orang/read?key=vr46",
method: "GET",
data: {}
})
.then(function(response) {
$scope.myData = response.data;
$scope.hide();
$scope.orangs = angular.toJson($scope.myData.data);
console.log('Response Data', $scope.orangs);
});
})
这是我的codeigniter rest_server控制器:
<?php
require(APPPATH.'libraries/REST_Controller.php');
class Orang extends REST_Controller {
public function __construct(){
parent::__construct();
date_default_timezone_set("Asia/Jakarta");
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
}
// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers:
{$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
exit(0);
}
}
function read_get()
{
$data = $this->db->order_by('id', 'DESC')->get('orang')->result();
if($data){
$response['data'] = $data;
$response['status'] = 1;
}else{
$response['status'] = 0;
$response['message'] = 'Data tidak ada';
}
$this->response($response);
}
}
我使用codeigniter rest服务器来获取数据。
答案 0 :(得分:0)
按$ index&#39;添加&#39;你的ng-repeat。
$list = [
["Name" => "John", "Gender" => "M"],
["Name" => "Doe", "Gender" => "M"],
["Name" => "Sara", "Gender" => "F"]
];
$csvArray = ["header" => implode (",", array_keys($list[0]))] + array_map(function($item) {
return implode (",", $item);
}, $list);
file_put_contents($filename, implode ("\n", $csvArray));
Angular并不喜欢它的中继器中的重复键。这将通过他们的索引来跟踪它们。请参阅more detailed explanation here。