简单的Angular.js:ng-repeat不显示数据

时间:2015-10-29 11:18:08

标签: javascript html angularjs

我正在尝试使用一个简单的angular.js脚本,只需从mysql数据库获取信息并通过ng-repeat显示它们。该网站只是空白,没有错误或类似的东西...所以我建议我在这里遇到一个逻辑问题。

控制器:

var app = angular.module('ISPapp', []);
app.controller('artikelController', function($scope, $http) {
	
	getArtikel();
	
	function getArtikel(){
		$http.post("ajax/get_artikel.php").success(function(data){
		$scope.artikel_entrys = data;
		});
	};

});

输出:

<table ng-controller="artikelController">

<thead><tr><th>ID</th><th>Artikelnr</th><th>Kit</th><th>Min Bestand</th><th>Beschreibung</th>< tr></thead>

<tbody>

<tr ng-repeat="row in artikel_entrys">
	<td>{{row.id}}</td>
	<td>{{row.artikelnr}}</td>
	<td> Test </td>
	<td>{{row.min_bestand}}</td>
	<td>{{row.beschreibung}}</td>
</tr>

</tbody> </table>

指数:

<!DOCTYPE html>

<html ng-app="ISPapp">

<head>
	<script type="text/javascript" src="js/angular.min.js"></script>
	<script type="text/javascript" src="js/app.js"></script>
</head>

<body ng-controller="artikelController">

<div ng-include src="app/artikel.html"></div>

</body>

</html>

来自PHP的json对象很好。

提前感谢您的帮助!

GZ 垫

3 个答案:

答案 0 :(得分:1)

问题出在我身边,因为我的ng-repeat不在我的控制器之外。检查,这可能对某人有帮助。

答案 1 :(得分:0)

使用ng-repeat的方式用于数组。

要浏览JSON对象,您必须采取其他方式

<div ng-repeat="(key, value) in myObj"> ... </div>

答案 2 :(得分:0)

我尝试了一些其他的东西,现在它正在使用这段代码:

索引HTML

<!doctype html>
<html ng-app>
<head>
<title>ISP Artikel</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>
<script src="script.js"></script>
</head>

<body>
<div ng-controller="getArtikel">

<table>
<thead><tr><th>ID</th><th>Artikel Nr</th><th>Beschreibung</th></tr></thead>
<tbody>
<tr ng-repeat="row in artikel_entrys"><td>{{row.id}}</td><td>{{ row.artikelnr }}</td><td>{{row.beschreibung}}</td></tr>
</tbody>
</tfoot></tfoot>
</table>

</div>
</body>

这个Javascript片段

function getArtikel($scope, $http) {
    // this is where the JSON from api.php is consumed
    $http.get('ajax/get_artikel.php').
        success(function(data) {
            // here the data from the api is assigned to a variable named users
            $scope.artikel_entrys = data;
        });
}

与之前的PHP Api相同。相同的Json对象......

我很高兴它现在有效,但任何人都可以解释我以前做错了什么吗? : - )

相关问题