Using the Location service with @angular/upgrade

I don’t know if there is already a post somewhere about this, but when I had this problem a few weeks ago (more like 2 months ago) I couldn’t find anything about how to use the Location service from Angular 2 online.

So, you might be in the same situation I am where you’re migrating an Angular 1 web application to Angular 2 (I’m going to start calling Angular 1 NG1 and Angular 2 NG2 because… laziness), which means running both frameworks side by side. If your situation is similar to mine, you may be running NG2 components in your NG1 app and still using NG1’s router.

That’s cool and all, but now you may want to navigate to another route from within your NG2 controller. You could upgrade the $location service and use that, and that would probably be fine but, like me, you probably want to use NG2 services as much as possible so here’s how you setup the Location service in NG2. It’s actually quite simple.

Continue reading “Using the Location service with @angular/upgrade”