Angular 2! Why did you invent a beautiful slow and useless code? – for(var key in response.json())

this.http.get(url, this.options).subscribe(
    response => {
        for (var key in response.json()) {
            if (response.json().hasOwnProperty(key)) {
               // code here

Angular 2!  Why did you invent the code above?  Pretty to look at but very slow and useless!  Is it just because for the show! or is it, that we novice, didn’t know how to use it.  Regardless,  it is 1,000 x slower than a standard JQuery AJAX call.  Do not use it guys!  Instead follow the code below, which is an alternative code provided by my colleague.

this.http.get(url, this.options).subscribe(
    response => {
        var newResponse = new wijmo.collections.ObservableArray(response.json());
        for (var i = 0; i < newResponse.length; i++) {
               // code here

The above code transfers the response values to a new array, in the code, we used premium controls, e.g., wijmo, but you can use any array objects for your projects.  This code is so much faster than the first one, which most of the Internet Angular 2 examples on services is based upon.  Below is the sample complete code on real application.


And if you find this blog helpful, you can make the donation by clicking the Paypal button below.


Software developer living in the Philippines.

Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Harold Glenn P. Minerva
Software Developer / Tech Enthusiast
Living in the Philippines

View Harold Glenn Minerva's profile on LinkedIn


Software Engineer - Seasonal and Range Trading Software. Magenta Trader is a powerful stock market visualization software that increases your probability of trading success.

Software Architect and Founder - is a multi-tenant cloud-based Software-as-a-Service (SaaS) business app that caters to micro, small and medium trading businesses.

CTO and Co-Founder - We give your company the leverage by providing innovative software solutions products such as Point-of-Sales (POS), Financial Information System (FMIS), Payroll and DTR (HRIS), and many more.

%d bloggers like this: