angularjs-ng-repeat - 角度js ng-repeat不起作用
问题描述
在 ng-repeat 中不显示任何数据,但数据可用于响应。循环不能正常工作。
<html>
<head></head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body ng-app="myApp">
<div ng-controller="thecontroller">
<form>
<tr ng-repeat="x in names">
<td>{{x.name}}</td>
<td>{{x.email}}</td>
<td>{{x.passward}}</td>
</tr>
</form>
</div>
</body>
console.log(response) 在控制台中显示数据
<script>
var app = angular.module('myApp', []);
app.controller('thecontroller', function($scope, $http) {
$http.get("show.php")
.then(function (response) {
$scope.names=response.data;
console.log(response)
} );
});
</script>
</html>
解决方案
因此,我尝试了您的代码并进行了一些更正,您看不到任何数据的原因可能是由于使用tr
andtd
没有table
标签作为父标签的标签,请检查我的以下代码,我在其中添加了table
andtbody
标签, 另外,为了模拟一个http
请求,我使用了$timeout
3 秒后设置数据的,请研究示例并将其实现到您的代码中!
var app = angular.module('myApp', []);
app.controller('thecontroller', function($scope, $http, $timeout) {
var data = [{
name: "one",
email: "one@one.com",
password: "1234"
}, {
name: "two",
email: "two@two.com",
password: "1234"
}, {
name: "three",
email: "three@three.com",
password: "1234"
}, ]
$timeout(function() {
$scope.names = data;
}, 3000);
/*$http.get("show.php")
.then(function(response) {
$scope.names = response.data;
console.log(response)
});*/
});
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
</head>
<body ng-app="myApp">
<div ng-controller="thecontroller">
<form>
<table>
<tbody>
<tr ng-repeat="x in names">
<td>{{x.name}}</td>
<td>{{x.email}}</td>
<td>{{x.password}}</td>
</tr>
</tbody>
</table>
</form>
</div>
</body>
</html>
推荐阅读
- python - 将带有滞后功能的查询转换为带有烧瓶的 sqlalchemy?
- javascript - 在 React Native 中卸载组件期间,清理功能在 UseEffect Hook 中不起作用
- pentaho - 删除字符串 pentaho 前面的特殊字符
- angular - 值未在 Angular 中发布到 Nodejs API
- java - 在 Java XShell 平台中,退格显示为 ^H,删除显示为 ^[[3~
- c# - UWP 启动 Win32 控制台应用程序与 Process.Start 一起工作
- java - Jackson 可以为违反 Map 合同的 Map 生成重复的 JSON 对象属性名称吗?
- flutter - 在颤动中单击浮动操作按钮时添加新小部件
- azure-functions - OrchestrationTrigger 无法访问已处置的对象
- javascript - 有没有办法在柏树中重复整个 describe() 而不是 it() (简单案例)?