首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >类型“”Subscription“”缺少类型“”typeof Subscription“”的以下属性: prototype,空

类型“”Subscription“”缺少类型“”typeof Subscription“”的以下属性: prototype,空
EN

Stack Overflow用户
提问于 2020-06-24 23:42:03
回答 1查看 336关注 0票数 0
代码语言:javascript
复制
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";

//这些是我的导入

代码语言:javascript
复制
@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个错误1TypeOf Subscription类型上不存在->属性'unsubscribe‘。2 ->类型“”Subscription“”缺少类型“”typeof Subscription“”的以下属性: prototype,空

我已经包括了订阅和我需要的东西,但我不明白为什么我仍然得到这个错误。有人能帮帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2020-10-18 16:41:01

我也犯了这个简单的错误,找不到拼写错误。这行代码:

代码语言:javascript
复制
private drawerSub = Subscription;

应该是:

代码语言:javascript
复制
private drawerSub: Subscription;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62558904

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档