Retrieve list data using AngularJS REST API in SharePoint 2013

This SharePoint tutorial explains, how to get the data from SharePoint List using AngularJs and Rest API. I used REST API to talk to SharePoint and get the data from the list. I am not going to discuss much the REST services as many folks have already done great work on explaining about REST API service.

Retrieve list data using AngularJS REST API in SharePoint 2013

In this script we just saw, we have first created an Angular Controller with the name ‘spCustomerController’. We have also injected $scope and $http service. The $http service will fetch the list data from the specific columns of SharePoint list. $scope is a glue between the Controller and a View. It acts as an execution context for Expressions. Angular expressions are code snippets that are usually placed in bindings such as {{ expression }}.

Retrieve list data using AngularJS REST API in SharePoint 2013
Retrieve list data using AngularJS REST API in SharePoint 2013
<h1>WelCome To Angular JS Sharepoint 2013 REST API !!</h1>
<div ng-app="SharePointAngApp" class="row">
<div ng-controller="spCustomerController" class="span10">
<table class="table table-condensed table-hover">
<tr>
<th>Title</th>
<th>Employee</th>
<th>Company</th>
</tr>
<tr ng-repeat="customer in customers">
<td>{{customer.Title}}</td>
<td>{{customer.Employee}}</td>
<td>{{customer.Company}}</td>
</tr>
</table>
</div>
</div>

In the view, you can use the ng-repeat to iterate through the customers and display customer information.

Use the following procedure to create a sample.

Step 1: Navigate to your SharePoint 2013 site.

Step 2: From this page select Site Actions | Edit Page:

Edit the page, go to the “Insert” tab in the Ribbon and click the “Web Part” option. In the “Web Parts” picker area, go to the “Media and Content” category, select the “Script Editor” Web Part and press the “Add button”.

Step 3: Once the Web Part is inserted into the page, you will see an “EDIT SNIPPET” link; click it. You can insert the HTML and/or JavaScript as in the following:

<style>
table, td, th {
border: 1px solid green;
}
th {
background-color: green;
color: white;
}
</style>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
<script src="https://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
<script>

var myAngApp = angular.module('SharePointAngApp', []);
myAngApp.controller('spCustomerController', function ($scope, $http) {
$http({
method: 'GET',
url: _spPageContextInfo.webAbsoluteUrl + “/_api/web/lists/getByTitle('InfoList')/items?$select=Title,Employee,Company",
headers: { "Accept": "application/json;odata=verbose" }
}).success(function (data, status, headers, config) {
$scope.customers = data.d.results;
}).error(function (data, status, headers, config) {
});
});
</script>

<h1> Angular JS SharePoint 2013 REST API !!</h1>
<div ng-app="SharePointAngApp" class="row">
<div ng-controller="spCustomerController" class="span10">
<table class="table table-condensed table-hover">
<tr>
<th>Title</th>
<th>Employee</th>
<th>Company</th>
</tr>
<tr ng-repeat="customer in customers">
<td>{{customer.Title}}</td>
<td>{{customer.Employee}}</td>
<td>{{customer.Company}}</td>
</tr>
</table>
</div>
</div>

Finally result show below:

Retrieve list data using AngularJS REST API in SharePoint online
Retrieve list data using AngularJS REST API in SharePoint online

You may like following SharePoint Rest API tutorials:

Hope this SharePoint tutorial explains, how to retrieve list data using AngularJS and Rest API in SharePoint 2013/2016 or SharePoint Online.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>