简体   繁体   English

如何使用Angular Js以从node.js服务器检索的表格式显示json数据

[英]How to show json data in a table format retrieved from node.js server using Angular Js

This is an index file I had made to display the json data though angular.js 这是我制作的一个索引文件,用于通过angular.js显示json数据

<!DOCTYPE html>
<html>
<head>
<style>
table, th , td {
border: 1px solid grey;
border-collapse: collapse;
padding: 5px;
}
table tr:nth-child(odd) {
background-color: #f1f1f1;
}
table tr:nth-child(even) {
background-color: #ffffff;
}
</style>
<script src= “http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js”></script>
</head>
<body>

<div ng-app=”” ng-controller=”blogController”>

<table>
<tr><td>Manger Id</td><td>Manger Name</td></tr>
  <tr ng-repeat=”x in name”>
    <td>{{ x.m_id }}</td>

<td>{{ x.name }}</td>


  </tr>
</table>

</div>

<script>
function blogController($scope,$http) {
$http.get('http://localhost:3000/techgeek/v1/getEmployeeDetails')
.success(function(response) {
    $scope.names = response;
    console.log($scope.names);
});
}
</script>

</body>
</html>

I am unable to get the json data from nodejs server. 我无法从nodejs服务器获取json数据。 I aslo attacted a secreen shout my json data genereated though nodejs sever . 我还通过nodejs切断了对我的json数据的保密提示。 在此处输入图片说明 . The main problem with url. 网址的主要问题。 Thanks for your help in advance 谢谢您的帮助

Here is the live for your problem. 这是为您解决的问题。 I have solved it using the local Json. 我已经使用本地Json解决了它。 You have made the following mistakes as below 您犯了以下错误:

  1. ng-repeat names should be there as you have $scope.names in your controller. ng-repeat名称应该在那里,因为您的控制器中有$ scope.names。
  2. x.name in the second column which is wrong as your json is having the x.m_name as the field. x.name第二栏为您的JSON是具有x.m_name作为字段这是错误的。
  3. Also, I have a doubt if the node.js server and the angular application is running in the same port, else you might get CORS (Cross Origin Resource Sharing) error in the console which you have to fix it. 另外,我怀疑node.js服务器和angular应用程序是否在同一端口上运行,否则您可能会在控制台中收到CORS (跨源资源共享)错误,必须对其进行修复。

Plunker 柱塞

   <tr><td>Manger Id</td><td>Manger Name</td></tr>
   <tr ng-repeat="x in names track by $index">
        <td>{{ x.m_id }}</td>
        <td>{{ x.m_name }}</td>
   </tr>

Update 1 更新1

You have a problem with the module as you have used ng-app="" in your code please fix it by using a module as below 您的模块有问题,因为您在代码中使用了ng-app="" ,请使用以下模块进行修复

var app = angular.module('plunker', []);
app.controller("",function(){
 .....................
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Angularjs中创建的网站中显示数据,从SQL Server检索到Node.js的数据 - How to display data in website created in Angularjs , data retrieved from SQL Server to Node.js 如何使用Angular.js在页面上显示从JSON检索的图像 - How to show images retrieved from JSON on page using Angular.js Node.js从服务器渲染大量JSON数据 - Node.js Rendering big amount of JSON data from the server 如何使用Angular JS显示json的完整数据列表? - How to show the full list of data from json using Angular JS? 从node.js服务器运行angular - Running angular from node.js server 如何通过一个端点将数据从Angular传递到Node.Js服务器,反之亦然? - How can I pass data from Angular to Node.Js server and vice versa by one endpoint? 如何使用angular.js,socket.io,node.js在聊天应用程序中显示活动用户列表 - How to show active userlist in chat application using angular.js , socket.io, node.js 无法将数据从Angular.js发布到Node.js - Cannot post data from Angular.js to Node.js Angular JS声明控制器,使用从PHP文件检索的数据 - Angular JS declare controller using data retrieved from PHP file 无法使用有角度的URL路由来获取JSON形式的node.js / express服务器的json-(newbie) - Having trouble fetching json form node.js/express server using angular, probably url routing -(newbie)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM