angular - 类型 'distinctUntilChanged' 上不存在属性 'Observable<Event>'

标签 angular angular5 angular6 rxjs5 rxjs6

尝试从 Angular 5 升级到 Angular 6 并收到此错误:

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");
    });

我在这里缺少什么?

最佳答案

import { distinctUntilChanged } from 'rxjs/operators';

router.events.pipe(distinctUntilChanged((previous: any, current: any) => {})).subscribe();

关于angular - 类型 'distinctUntilChanged' 上不存在属性 'Observable<Event>',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52758954/

相关文章:

angular-cli - Angular 5 Service Workers 缓存刷新数据更新或插入

javascript - 如何对所有路由 Root 和 Child Routes 使用 angular 6 Route Auth Guards?

javascript - 在 Angular 6 中注入(inject) Rollbar

angular - 如何在电脑启动时自动运行 ng 服务

Angular 4 Reactive Forms 切换隐藏表单元素的验证

Angular 路由器事件 : NavigationEnd -- How to filter only the last event

未触发 Angular 4 动画, "ng-animate-queued"类已添加到元素

angular - Primeng 使用样式时找不到不同的支持对象 'width: 100%'

angular - RxJS 6 switchMap 弃用符号使用

仅适用于网站模块的 Angular Universal