Breeze using angular $http interceptor Breeze using angular $http interceptor angularjs angularjs

Breeze using angular $http interceptor


using the setHttp method works for me to use http interceptors with the breeze angular ajax adapter. in my environment, it looks like this:

(function() {    'use strict';    var serviceId = 'entityManagerFactory';    angular.module('app').factory(serviceId, ['$http', emFactory]);    function emFactory($http) {        var instance = breeze.config.initializeAdapterInstance("ajax", "angular");        instance.setHttp($http);        ...    }})();

the only place I've really found any information about this is in the release notes for 1.4.4 on the download page. I don't really understand what this does. i'm sure one of the breeze guys will have a better explanation.


You have to call setHttp($http) as explained by @almaplayera. Please mark his as the correct answer.

Here's why that is necessary.

By default, the breeze angular ajax adapter initializes itself with whatever instance of $http is available. Unfortunately, at the time that most scripts are loading, the $http instance for YOUR APP hasn't been created. That won't happen until your module loads ... which typically happens long after breeze loads.

So rather than create an adapter that won't work at all, breeze spins up its own instance of $http and wires the angular ajax adapter to that instance.

If your code doesn't do anything special, this works fine. It's not optimal; you'll get one extra $digest cycle than necessary. But it works for most people and let's admit that there is more than enough configuration noise to deal with as it is.

But you ARE doing something special. You're configuring a very specific instance of $http, not the one that breeze created for itself.

So you have to tell breeze to use YOUR instance of $http ... and that's what happens when you call setHttp($http);

Thanks to this feedback I have updated the breeze documentation on ajax adapters to describe how to configure for an Angular app.