Thursday, August 4, 2016

Upgrading Angular 2 from beta 17 to RC4–Lessons learned Part 2

This is a continuation of a previous blog post found here: http://bartwullems.blogspot.be/2016/08/upgrading-angular-2-from-beta-17-to.html

New router

We’re almost there. With the upgrade from beta to RC the Angular team throw away their first Angular 2 router implementation and build a new one. Let’s fix our code to use the updated router…

In my original code I had the following:

I updated it to the following:

Next, I extracted the router config to a seperate file and created a provider to load it inside the Angular bootstrap logic:

The code to get router data changes as well:

The information from the current route is accessible through the ActivatedRoute object. This is an observable and inside your component you can subscribe for changes. However in this sample I used the snapshot property which captures only the state on the moment we navigated to the component(which is sufficient for this example).

More information about the “new new” router can be found in the documentation: https://angular.io/docs/ts/latest/guide/router.html

No comments: