属性 'distinctUntilChanged' 在类型 'Observable<Event>' 上不存在
Property 'distinctUntilChanged' does not exist on type 'Observable<Event>'
尝试从 5 升级到 Angular6 并遇到此错误:
ERROR in src/app/app.component.ts(26,23): error TS2339: Property
'distinctUntilChanged' does not exist on type 'Observable'.
我在 app.module.ts 中导入了 distinctUntilChanged:
import "rxjs/add/operator/distinctUntilChanged";
我的代码在 app.component.ts 中:
import { Component } from "@angular/core"; import { Router, NavigationEnd } from "@angular/router";
import { TranslateService } from "@ngx-translate/core";
import { GeoService } from "app/services/geo.service";
import { ArbeteService } from "app/services/arbete.service";
import { GoogleAnalyticsEventsService } from "app/services/google-analytics-events.service";
import * as _ from "lodash";
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.scss"]
})
export class AppComponent {
//Send pageview to Google Analytics
router.events.distinctUntilChanged((previous: any, current: any) => {
if (current instanceof NavigationEnd) {
return previous.url === current.url;
}
return true;
}).subscribe((x: any) => {
googleAnalytics.emitVirtualPageView("Rekryteringsguiden", "Rekryteringsguiden");
});
我在这里错过了什么?
从 rxjs 5.5 导入运算符
import { distinctUntilChanged } from 'rxjs/operators';
对于 Angular 6,大多数 RxJS 运算符的语法都会发生变化。
要导入它,请使用:
import { catchError } from 'rxjs/operators';
但是调用必须包裹在pipe
中,像这样:
router.events
.pipe(
distinctUntilChanged((previous: any, current: any) => {
if (current instanceof NavigationEnd) {
return previous.url === current.url;
}
return true;
})).subscribe((x: any) => {
googleAnalytics.emitVirtualPageView("Rekryteringsguiden", "Rekryteringsguiden");
});
import { distinctUntilChanged } from 'rxjs/operators';
router.events.pipe(distinctUntilChanged((previous: any, current: any) => {})).subscribe();
尝试从 5 升级到 Angular6 并遇到此错误:
ERROR in src/app/app.component.ts(26,23): error TS2339: Property 'distinctUntilChanged' does not exist on type 'Observable'.
我在 app.module.ts 中导入了 distinctUntilChanged:
import "rxjs/add/operator/distinctUntilChanged";
我的代码在 app.component.ts 中:
import { Component } from "@angular/core"; import { Router, NavigationEnd } from "@angular/router";
import { TranslateService } from "@ngx-translate/core";
import { GeoService } from "app/services/geo.service";
import { ArbeteService } from "app/services/arbete.service";
import { GoogleAnalyticsEventsService } from "app/services/google-analytics-events.service";
import * as _ from "lodash";
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.scss"]
})
export class AppComponent {
//Send pageview to Google Analytics
router.events.distinctUntilChanged((previous: any, current: any) => {
if (current instanceof NavigationEnd) {
return previous.url === current.url;
}
return true;
}).subscribe((x: any) => {
googleAnalytics.emitVirtualPageView("Rekryteringsguiden", "Rekryteringsguiden");
});
我在这里错过了什么?
从 rxjs 5.5 导入运算符
import { distinctUntilChanged } from 'rxjs/operators';
对于 Angular 6,大多数 RxJS 运算符的语法都会发生变化。
要导入它,请使用:
import { catchError } from 'rxjs/operators';
但是调用必须包裹在pipe
中,像这样:
router.events
.pipe(
distinctUntilChanged((previous: any, current: any) => {
if (current instanceof NavigationEnd) {
return previous.url === current.url;
}
return true;
})).subscribe((x: any) => {
googleAnalytics.emitVirtualPageView("Rekryteringsguiden", "Rekryteringsguiden");
});
import { distinctUntilChanged } from 'rxjs/operators';
router.events.pipe(distinctUntilChanged((previous: any, current: any) => {})).subscribe();