Being a novice to angularjs framework I'm attempting to use a controller to retrieve a JSON and display elements,but the desired result is not displayed.
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/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>
Controller : processJson.js
var getJson = angular.module('getJson', []).controller('controller1', function ($scope, $http) {
var url = "../../routes/fields.js";
console.log(url);
$http.get(url).success(function (data) {
$scope.posts = data;
});
});
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;
Also utilising mongodb to store and retrieve as JSON data.. URL http://localhost:3000/fields/fieldlist returns my json array stored in mongodb.