Angularjs未在表行中显示更新数据,ng repeat工作不正常?
我正在尝试使用Angular来显示我从数据库和控制台中提取的JSON数据,并按预期打印数据,但表ng重复显示不显示数据。即使是表外数据也能正确显示 {{联系人列表[0]。姓名}Angularjs未在表行中显示更新数据,ng repeat工作不正常?,angularjs,angularjs-ng-repeat,Angularjs,Angularjs Ng Repeat,我正在尝试使用Angular来显示我从数据库和控制台中提取的JSON数据,并按预期打印数据,但表ng重复显示不显示数据。即使是表外数据也能正确显示 {{联系人列表[0]。姓名} <!DOCTYPE> <html ng-app="nodeapp"> <head> <title>AngularJs with Nodejs</title> <!-- Latest compiled and minified CSS --
<!DOCTYPE>
<html ng-app="nodeapp">
<head>
<title>AngularJs with Nodejs</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
</head>
<body>
<div class="container" ng-controller="nodeappctrl">
<div class="row">
<h1>Angularjs with api's</h1>
<p>{{contactlists[0].name}}</p>
</div>
</div>
<div class="container">
<div class="row">
<table class="table">
<thead>
<tr>
<th>SNo</th>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="contact in contactlists">
<td>{{$index}}</td>
<td>{{contact.name}}</td>
<td>{{contact.email}}</td>
<td>{{contact.number}}</td>
</tr>
</tbody>
</table>
</div>
</div>
<script src="https://code.angularjs.org/1.4.9/angular.min.js"></script>
<script type="text/javascript">
var nodeapp = angular.module('nodeapp', []);
nodeapp.controller('nodeappctrl', ['$scope', '$rootScope', '$log', '$http',
function($scope, $rootScope, $log, $http) {
var contactlist = {};
$http.get('/contactlist').success(function(data) {
$scope.contactlists = data;
//$scope.$apply();
console.log(JSON.stringify($scope.contactlists), null,2);
});
}
]);
</script>
<!--
// dummy data
var contactlists =[
{
name: 'Rajesh',
email: 'raj@g.com',
number: '11 - 111 - 11111'
}, {
name: 'Rajesh2',
email: 'raj2@g.com',
number: '22 - 222 - 222222'
}, {
name: 'Rajesh3',
email: 'raj3@g.com',
number: '33 - 333 - 333333'
}
]-->
</body>
</html>
</html>
带Nodejs的AngularJs
带api的Angularjs
{{联系人列表[0]。姓名}
斯诺
名称
电子邮件
电话
{{$index}}
{{contact.name}
{{contact.email}
{{contact.number}
var nodeapp=angular.module('nodeapp',[]);
nodeapp.controller('nodeappctrl'、['$scope'、'$rootScope'、'$log'、'$http',
函数($scope、$rootScope、$log、$http){
var contactlist={};
$http.get('/contactlist').success(函数(数据){
$scope.contactlists=数据;
//$scope.$apply();
log(JSON.stringify($scope.contactlist),null,2);
});
}
]);
问题在于:
<div class="container" ng-controller="nodeappctrl">
nodeappctrl控制器应应用于作为访问其作用域的父级的标记。如您所见,该表是控制器绑定到的元素的同级的子级
例如,将ng controller=“nodeappctrl”
移动到body标签。问题在于:
<div class="container" ng-controller="nodeappctrl">
nodeappctrl控制器应应用于作为访问其作用域的父级的标记。如您所见,该表是控制器绑定到的元素的同级的子级
例如,将
ng controller=“nodeappctrl”
移动到body标签。将ng controller
放置在
标签内。
您在已关闭的
中使用了它,因此代码底部的其余部分无法使用它
<body ng-controller="nodeappctrl">
//your code here..
</body>
//你的代码在这里。。
将ng控制器
放置在
标签内。
您在已关闭的
中使用了它,因此代码底部的其余部分无法使用它
<body ng-controller="nodeappctrl">
//your code here..
</body>
//你的代码在这里。。
创建一个plunker,我会帮忙。创建plunker,我会帮忙。