Html 使用AngularJS显示json数组的元素
作为angularjs框架的新手,我尝试使用一个控制器来检索JSON和显示元素,但是没有显示所需的结果 index.htmlHtml 使用AngularJS显示json数组的元素,html,angularjs,Html,Angularjs,作为angularjs框架的新手,我尝试使用一个控制器来检索JSON和显示元素,但是没有显示所需的结果 index.html <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/a
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/X.Y.Z/angular-route.js"></script>
<script src="../public/javascripts/processJson.js"></script>
</head>
<body>
<div ng-app="getJson"><div ng-controller="controller1">
<div ng-repeat="post in posts">
<div ng-switch-when="text"><input type="text" id="{{post.id}}" ng-model="post.value" placeholder="{{post.placeholder}}">
</div>
</div>
</div>
</div>
</body>
</html>
fields.js
var express=require('express');
var router =express.Router();
router.get('/fieldlist',function(req,res){
var db=req.db;
var collection=db.get('domlist');
collection.find({},{},function(e,docs){
res.json(docs);
});
});
module.exports=router;
还利用mongodb存储和检索JSON数据。。URL返回存储在mongodb中的json数组。您能试试
$scope.posts=data.data
HTTP请求将返回一个包含以下数据属性的对象:
响应对象具有以下属性:
数据{string | Object}–使用
变换函数。状态–{number}–的HTTP状态代码
答复。headers–{function([headerName])}–Header getter函数。
config–{Object}–用于生成
请求。statusText–{string}–响应的HTTP状态文本
有关详细信息:您有一个ng开关,但周围没有ng开关,这会导致我出错:
Error: [$compile:ctreq] Controller 'ngSwitch', required by directive 'ngSwitchWhen', can't be found!
我准备了一个JSIDLE你能给我们展示一下JSON的样子吗?请包括你面临的问题?您是否在$scope.posts中获得了所需的数据?@PhilKearney添加了更多信息code@Navaneeth添加了更多代码
Error: [$compile:ctreq] Controller 'ngSwitch', required by directive 'ngSwitchWhen', can't be found!