Compressed JSON response does errors when used in Service

572 views
Skip to first unread message

Nikolay Krustev

unread,
Apr 8, 2013, 12:12:18 PM4/8/13
to ang...@googlegroups.com
Hello, 
I am kind of new to AngularJS, so it can be my fault, but since there is so little info I need to ask for help.
In my application I load a JSON that is pretty huge (~ 10000 products). Load times are horrible without compression, as you can imagine and I decided to use gzip compression.
I compress the json response from my REST service (I use Slim). I load my data  async via an angular service. It works fine with the uncompressed response. This is my code:
 app.factory('CatalogService',function($http)
{
    var productsUrl = 'products/';
    var service =
    {
        async: function ()
        {
            var promise = $http({method:'GET', url: productsUrl, cache:true}).then(function (result) {
                var compressed = result.data;
                var decomp = JXG.decompress(compressed);
                return decomp;
            });
            return promise;
        }
    };
    return service;
});

The code itself works and debug inspection shows that the response is decompressed fine back to the original. However my templates does not load anything, and I get "undefined" errors on one of my custom filters that inspects a response element length.
Any help is appreciated.

yahya Kacem

unread,
Apr 8, 2013, 4:27:16 PM4/8/13
to ang...@googlegroups.com
I never used compression but, just a thought, maybe after the data is compressed is not a json object anymore check the type of the decompressed data it's probably string not Json.
Hope this help.

Nikolay Krustev

unread,
Apr 10, 2013, 5:06:32 AM4/10/13
to ang...@googlegroups.com
Thank you, that was the problem. I just eval'd it (I am certain about the safety of the JSON since I generate it, so eval is not a security hole) and it works like a charm. 
Reply all
Reply to author
Forward
0 new messages