angular-middleware icon indicating copy to clipboard operation
angular-middleware copied to clipboard

plugins.js:2 TypeError: Cannot read property 'next' of undefined

Open stefensuhat opened this issue 9 years ago • 1 comments

Hi,

I always get those error when setup the middleware. here is my code:

 $middlewareProvider.map({ 

            'check-token': ['Auth', (Auth) => {
                const request = this;
                Auth.get({ url: 'check-token' }, response => {
                    if (response) {
                        return request.next();
                    }
                });
            }]
        });

stefensuhat avatar Aug 09 '16 03:08 stefensuhat

I haven't tried it yet, but it looks like you are using those new fancy arrow functions, which implicitly binds "this" to the parent object. I think, but I'm not sure without checking, that "this" is actually referencing the map object and not the request. Give it a try without the arrow functions and let me know. I'll be happy to look into it more if that's not the case.

karlhepler avatar Jan 27 '17 04:01 karlhepler