December 2018
Intermediate to advanced
196 pages
4h 48m
English
Let’s hook up some analytics trackers to Angular’s router. Instead of listening in on individual routes, this service needs to know about every route change. Generate a new service and attach it to the routing module with ng g service analytics.
|
| Make sure you’re on the latest version of the Angular CLI. Older versions will fail, with “Error: Specified module does not exist.” |
Open the fresh analytics.service.ts and modify it to add in some structure for recording routing changes:
| | import { Injectable } from '@angular/core'; |
| | |
| | @Injectable({ |
| | providedIn: 'root' |
| | }) |
| | export ... |
Read now
Unlock full access