From c8323a965cf811b91a095710250c87607d6d5ad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BE=E5=87=A0=E6=B5=B7?= Date: Sat, 10 Oct 2020 00:33:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=AE=A2=E9=98=85=E6=9C=AA=E5=8F=96?= =?UTF-8?q?=E6=B6=88=E5=BC=95=E5=8F=91=E7=9A=84=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/view/write/write.component.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/app/view/write/write.component.ts b/src/app/view/write/write.component.ts index 775a0e8..f224c36 100644 --- a/src/app/view/write/write.component.ts +++ b/src/app/view/write/write.component.ts @@ -1,4 +1,4 @@ -import {Component, OnInit} from '@angular/core'; +import {Component, OnDestroy, OnInit} from '@angular/core'; import {ArticleReq} from '../../class/Article'; import {ActivatedRoute, Router} from '@angular/router'; import {ApiService} from '../../api/api.service'; @@ -17,7 +17,7 @@ import {Response} from '../../class/HttpReqAndResp'; templateUrl: './write.component.html', styleUrls: ['./write.component.less'] }) -export class WriteComponent implements OnInit { +export class WriteComponent implements OnInit, OnDestroy { constructor(private router: Router, private activatedRoute: ActivatedRoute, @@ -44,11 +44,12 @@ export class WriteComponent implements OnInit { title: string; private lastShowTime: number; + private userInfoSub: { unsubscribe: () => void } ngOnInit(): void { this.vditor = new Vditor('vditor', this.initOption()); // 用户权限判断 - this.userService.watchUserInfo({ + this.userInfoSub = this.userService.watchUserInfo({ complete: () => null, error: () => { if (!this.lastShowTime || Date.now() - this.lastShowTime > 1000) { @@ -79,6 +80,10 @@ export class WriteComponent implements OnInit { }); } + ngOnDestroy(): void { + this.userInfoSub.unsubscribe(); + } + // 提交按钮的事件 articleSubmit() {