使用AngularJS打印JSON值
Print JSON value using AngularJS
我正在尝试使用AngularJS从JSON端点打印一些数据。终点:- http://localhost:8081/api
{
"1": {
"venture": "XYZ Informatics",
"member": [
{
"name": "abcd",
"email": "abcd@gmail.com"
}
],
"message": "This is good day",
"isclicked": false
},
"2": {
"venture": "BBC Informatics",
"member": [
{
"name": "xyz",
"email": "xyz@gmail.com"
}
],
"message": "This is bad day",
"isclicked": false
}
}
我想在行中显示企业s的名称。我期望的行输出是:-
XYZ Informatics
BBC Informatics
My Code is:-
<!DOCTYPE html>
<html ng-app="MyApp">
<head>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 15px;
}
</style>
</head>
<body>
<div ng-app="MyApp" ng-controller="displayController">
<table style="width:100%">
<tr ng-repeat="data in datas">
<td>{{ data.venture }}</td>
</tr>
</table>
</div>
<script>
angular.module('MyApp', [])
.controller('displayController', function($scope, $http) {
var url = "http://localhost:8081/api";
$http.get(url).success(function (response) {
$scope.datas = response;
});
}
</script>
</body>
</html>
但是值没有显示。可能,我错过了进入JSON的每个数组。
您的脚本有语法错误。为你的控制器关闭括号
<script>
angular.module('MyApp', [])
.controller('displayController', function($scope, $http) {
//changed to your local api
var url = "http://localhost:8081/api";
$http.get(url).success(function(response) {
$scope.datas = response;
});
});//this is the place where you miss out the closing bracket
</script>
相关文章:
- 原始javascript将json对象中的项目打印到列表中的屏幕上
- 正在打印JSON属性
- 如何使用 JQuQuery 解析 JSON 对象并在 HTML 页面中以表格格式打印输出
- 从一个复杂的JSON对象打印每个JSON输入路径
- 如何在表中的HTML页面中打印解析的JSON数据
- 迭代JSON对象并将元素打印到屏幕上的最佳方式是什么
- 如何以类似 JSON 的格式打印圆形结构
- 在 nodejs 中有什么方法可以打印 JSON 格式的 log4js 输出
- 如何在控制台.log中打印 JSON 数据
- 将 JSON 数据解析为 SELECT 打印未定义
- 在 jquery 中打印 json 数组
- 如何使用 JQuery 以表格形式打印通用 json 结果
- 本地存储的 json 数组正在打印,但来自 json 的值在 cordova 应用程序中给出未定义
- 在 PHP 中打印包含 SVG 元素的 JSON 数组
- 当我添加额外的行进行重定向时,Highchart 不打印 json
- 如何通过JavaScript打印多维JSON对象
- 将多维JSON打印为html表单输入,名称为属性的xpath
- 将JSON打印到屏幕以用于剪切和粘贴
- 使用Angular将Json打印为HTML字符串
- 我如何从json打印密钥在我的网页上一个接一个