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.

untitled

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


		
Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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