Get Data from JSON file using Angularjs

Hi Friends,

In the below post we will learn how to fetch data of a json file using angular js. I will modify my previous example of a angular js to get some data from json file. I have created a json file at the same directory and named it as “groceryList.json” and added some predefined data as below in that fille.


next I have updated the “itemListCtrl” as below.


Code highlighting produced by Actipro CodeHighlighter (freeware)

--> myGroceryApp.controller("itemListCtrl", function ($scope,$http) {
= model;

"groceryList.json").success(function (data) {
= data;

= function (itemName, quantity) {
var srNo = $scope.itemList.items.length+1;
srNo: srNo,
itemName: itemName,
quantity: quantity,



Here I have added “$http” service at the controller parameter , then I have used “$http.get” method to fetch the data from “groceryList.json” file. In the success callback I have assigned the “$scope.itemList.items” with the returned data.

When you browse this ,you will see the below page as output.


I hope you found this post useful. Thanks for reading. Happy Coding Smile.


One thought on “Get Data from JSON file using Angularjs

  1. Hello, where do you acctually put the file ? I'm having trouble locating it in the local environment as well as the production environment. It always comes back with a 404 Not found Error .


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s