What I Learned Last Week — 2016.09.26

Someone wrote up a great table to show comparison of php types and their results

Link: http://php.net/manual/en/types.comparisons.php

Rest vs. RPC

Phil Sturgeon wrote up a great article in smashing magazine about knowing the difference between a RESTful web service and an RPC api… I’ve been mixing up names apparently.

Link: https://www.smashingmagazine.com/2016/09/understanding-rest-and-rpc-for-http-apis/

Google Maps Shows Gas Prices

Playing around with google maps, i Just found out that some gas stations (Wawa especially) now have gas prices overlaid on them

Angular 2 Child Routing

Angular 2 is my new favorite toy. But it was a bit challenging figuring out child routing… This is where you have a secondary navigation within a component so that the component can have it’s own navigation within itself (changing a part of the screen, not the whole app).

To accomplish this, you need to add a second router-outlet within your child component.

Say we have the following route: /contacts/:group where group is ‘friends’ or ‘enemies’ — we want to show a list of those friends. Now, we want a route /contacts/:group/:friend — where friend, is the id of the friend loaded into a component, we need to setup Child Routes like so:

{ path: 'contact/:group', component: ContactsListComponent, children: [ {path: '', component: EmptyContactComponent}, {path: ':id', component: ContactComponent} ]}

Now, the next challenge, is accessing the parent :group from the child.. that can be done by injecting ActivatedRoute and accessing the parent params like so.


Angular 2 Routing Events — Use NavigationEnd instead of NavigationStart

When subscribing to router events, so that you can update data on URL change, the tutorials i found online showed something like this..
 this._router.events.filter(event => event instanceof NavigationStart).subscribe(event => {
 While this sometimes works, i found it causes a race condition where the code fires before the navigation has actually completed – causing weird bugs… To solve this, use the NavigationEnd event instead, this will ensure all the navigation is completed before relying on the data for your objects.

Show your support

Clapping shows how much you appreciated Phil Palmieri’s story.