-1
Ich versuche, Google Analytics zu meinem Projekt hinzuzufügen, aber einige Navigationsfehler bekommen, ich neue Router verwenden, ist unter meinem Code:Angular 2 + Google Analytics + Router Navigation
// app.component.ts
declare var ga:Function;
export class App {
private currentRoute:string;
constructor(_router: Router, _location: Location) {
_router.events.subscribe((event:Event) => {
if(event instanceof NavigationStart) {
var newRoute = this._location.path() || '/';
if(newRoute !== this.currentRoute) {
ga('send', 'pageview', newRoute);
this.currentRoute = newRoute;
}
}
});
}
}
Und das ist der Fehler ich erhalte:
ERROR in [default] angular/src/app/app.ts:18:27
Argument of type '(event: Event) => void' is not assignable to parameter of type 'NextObserver<NavigationStart | NavigationEnd | NavigationCancel | NavigationError> | ErrorObserve...'.
Type '(event: Event) => void' is not assignable to type '(value: NavigationStart | NavigationEnd | NavigationCancel | NavigationError) => void'.
Types of parameters 'event' and 'value' are incompatible.
Type 'NavigationStart | NavigationEnd | NavigationCancel | NavigationError' is not assignable to type 'Event'.
Type 'NavigationStart' is not assignable to type 'Event'.
Property 'bubbles' is missing in type 'NavigationStart'.
ERROR in [default] angular/src/app/app.ts:19:23
Cannot find name 'NavigationStart'.
ERROR in [default] angular/src/app/app.ts:20:24
Property '_location' does not exist on type 'App'.
Hav Sie Navig importiert ationStart von @ angular/Router und Ort von @ angular/common –
Siehe http://StackOverflow.com/a/38448830/652850 und http://StackOverflow.com/A/38464412/652850 –
@ArpitAgarwal gestern selbst habe ich Import NavigationStart & end & das löste mein Problem .. :) –