SharePoint 2013/online – CRUD operations using AngularJS and REST

I’ve been developing some apps using AngularJS and REST.

Doing some Googleing I noticed that most developers use jQuery Ajax to make REST requests, however if you do that, you will miss out on some awesome AngularJS features.

First of all, you should check out this post on how to refresh the form digest value. You need the digest value to do CRUD operations or SharePoint will deny your requests.

Let’s create a SharePoint list with some custom fields. Note that the field internal names will be different from the display names, just to make the development easier.

(more…)

SharePoint – Refresh Form Digest Value using AngularJS and REST

Background

When working with SharePoint 2013/online, REST, CRUD and SPA you will need the Form Digest token. This a unique key based on user and and site and it’s only valid for a limited time.
Wictor Wilén wrote a very good post about it here

Problem

We have an App that is not using a master-page which means that the Form Digest value won’t update nor exist as a hidden input element. This means that we can not retrieve it using $(‘#__REQUESTDIGEST’).val(). Also, I have not been able to update the Digest value using UpdateFormDigest(relativeUrl,interval) from init.js.

Solution

Now, let’s build a service in AngularJS that will handle the Form Digest value for us and automatically update it with the same refresh rate as it would in the master-page. If you check the js-variable  _spFormDigestRefreshInterval on a page based on a master-page, you will find the value 1440000 (ms), which means that the Form Digest key will update every 24 minutes.

(more…)