类型“订阅”缺少类型“订阅类型”中的以下属性:原型,空

时间:2020-06-24 15:42:03

标签: nativescript-angular

import { Component, OnInit, OnDestroy, ViewChild, AfterViewInit, ChangeDetectorRef } from "@angular/core";
import { UIService } from "./shared/ui.service";
import { Subscription } from "rxjs";
import { RadSideDrawerComponent } from "nativescript-ui-sidedrawer/angular";
import { RadSideDrawer } from "nativescript-ui-sidedrawer";

//这些是我的进口货

@Component({
    selector: "ns-app",
    templateUrl: "./app.component.html"
})
export class AppComponent implements OnInit, OnDestroy, AfterViewInit {

    @ViewChild(RadSideDrawerComponent, { static: false }) drawerComponent: RadSideDrawerComponent;

    enteredChallenge: string[] = [];
    private drawerSub = Subscription; //I have put subscription here
    private drawer: RadSideDrawer;

    constructor (private uiService: UIService, private changeDetectionRef: ChangeDetectorRef) {}

    onChallengeInput(enterText: string){
        this.enteredChallenge.push(enterText);
    }

    ngOnInit(){
        this.drawerSub = this.uiService.drawerState.subscribe(
            () => {
                if(this.drawer){
                    this.drawerComponent.sideDrawer.toggleDrawerState();
                }
            }
        );
    }

    ngAfterViewInit(){

        this.drawer = this.drawerComponent.sideDrawer;
        this.changeDetectionRef.detectChanges();
    }

    ngOnDestroy(){
        if(this.drawerSub){
            this.drawerSub.unsubscribe();
        }

    }
 }

我有2个错误 1->属性'unsubscribe'在'typeof Subscription'类型上不存在。 2->类型“订阅”缺少类型“订阅类型”中的以下属性:原型,空

我已经包含了Subscription和我需要的东西,但我不明白为什么我仍然会收到此错误。有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

我也犯了一个简单的错误,无法发现错别字。 该行:

private drawerSub = Subscription;

应该是:

private drawerSub: Subscription;