我正在尝试使用AngularJs从Dhis2 Api获取数据。 。但数据未显示。我只是从api获取数据并在页面上显示名称和id。但我没有收到任何错误,但数据没有显示我不知道问题出在哪里。
这是我的角度js文件,我试图使用http.get从api获取数据。
angular.module('myApp', []).controller('userCtrl', function($scope,$http) {
init();
function init(){
var apiUrl = "http://localhost:8080/api/organisationUnits.json";
// Cross-site redirect error solution: Run chrome with --disable-web-security
var base64 = "YWRtaW46ZGlzdHJpY3Q=";
//$http.get(apiUrl, {headers: {'Authorization': 'Basic YWRtaW46ZGlzdHJpY3Q='}}).
$http.get(apiUrl, {headers: {'Authorization': 'Basic YWRtaW46ZGlzdHJpY3Q='}}).
success(function(data) {
// $scope.users = [];
$scope.users = data;
alert('success');
}).
error(function(data, status, headers, config) {
alert("Error. Data: " + data);
});
}
这是我的HTML页面。在我试图显示名称和我从API获得的ID。
<body ng-app="myApp" ng-controller="userCtrl">
<div class="container">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">DHIS2</a>
</div>
<div>
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<!--<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li> !-->
</ul>
</div>
</div>
</nav>
<h4>Search For the Organization Units</h4>
<div class="row">
<div class="col-sm-3 col-md-6" >
<input type="text" class="form-control" ng-model="filters.search" placeholder="Search for Organization Units">
</div>
<div class="col-sm-9 col-md-6" >
<label class="custom-select" >
<select ng-model="filters.searchdd">
<option selected disabled value="" style="display:block;"> Plese Select Level</option>
<option value="private">private</option>
<option value="simple">simple</option>
<option value="vip">vip</option>
</select>
</label>
</div>
</div>
<table class="table table-striped">
<thead><tr>
<th>Edit</th>
<th>Organizational Units</th>
<th>Levels</th>
<th>Drop Down Menu
</th>
</tr></thead>
<tbody><tr ng-repeat="user in users | filter:filters.search| filter: filters.searchdd">
<td>
<button class="btn" ng-click="editUser(user.id)" >
<span class="glyphicon glyphicon-pencil"></span> Edit
</button>
</td>
<td>{{ user.name }}</td>
<td>{{ user.id }}</td>
<td><label class="custom-select" >
<select ng-model="filters.searchdd">
<option selected disabled value="" style="display:block;"> Search or Edit</option>
<option value="1">Locate on Map</option>
<option value="2">Edit Coordinates</option>
<option value="3">Edit org. unit details</option>
<option value="4">Add new facility</option>
</select>
</label> </td>
</tr></tbody>
</table>
答案 0 :(得分:0)
您将数据传输到两个过滤器。您确定您的数据会通过吗?当然,似乎有一个缺少的结束括号,但也许你只是在复制时错过了它。