Tag Archives: Office PnP Core Js

Using Office PnP Core js with Angularjs

Angularjs is not the new kid on the block anymore and there are shinier Frameworks out there, but once in a while you have to deal with it. In my last project I used Angularjs in combination with Office PnP Core js. Office PnP Core js is great, but it uses ES6 Promises, which is really cool but unfortunate if you rely on Angularjs $q promises to fire up the digest cycle.

The Problem

Every time Office PnP Core js resolves a promise, we have to use scope.$apply to kick off the digest cycle and update our UI.

This is kind of anoying and error prone. If 2 requests finish nearly at the same time, it’s likely you will get a “a digest cycle is already in progress” exception.

The Solution

Luckily, Angular $q promises are ES6 compatible (“to some degree”) since Angular 1.3.x. Hence we can replace the Polyfill.

But be aware, that this will replace it for the whole browser window, other frameworks might need ES6 Promises anyway.