fix: 订阅未取消引发的异常
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import {Component, OnInit} from '@angular/core';
|
import {Component, OnDestroy, OnInit} from '@angular/core';
|
||||||
import {ArticleReq} from '../../class/Article';
|
import {ArticleReq} from '../../class/Article';
|
||||||
import {ActivatedRoute, Router} from '@angular/router';
|
import {ActivatedRoute, Router} from '@angular/router';
|
||||||
import {ApiService} from '../../api/api.service';
|
import {ApiService} from '../../api/api.service';
|
||||||
@@ -17,7 +17,7 @@ import {Response} from '../../class/HttpReqAndResp';
|
|||||||
templateUrl: './write.component.html',
|
templateUrl: './write.component.html',
|
||||||
styleUrls: ['./write.component.less']
|
styleUrls: ['./write.component.less']
|
||||||
})
|
})
|
||||||
export class WriteComponent implements OnInit {
|
export class WriteComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
constructor(private router: Router,
|
constructor(private router: Router,
|
||||||
private activatedRoute: ActivatedRoute,
|
private activatedRoute: ActivatedRoute,
|
||||||
@@ -44,11 +44,12 @@ export class WriteComponent implements OnInit {
|
|||||||
title: string;
|
title: string;
|
||||||
|
|
||||||
private lastShowTime: number;
|
private lastShowTime: number;
|
||||||
|
private userInfoSub: { unsubscribe: () => void }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.vditor = new Vditor('vditor', this.initOption());
|
this.vditor = new Vditor('vditor', this.initOption());
|
||||||
// 用户权限判断
|
// 用户权限判断
|
||||||
this.userService.watchUserInfo({
|
this.userInfoSub = this.userService.watchUserInfo({
|
||||||
complete: () => null,
|
complete: () => null,
|
||||||
error: () => {
|
error: () => {
|
||||||
if (!this.lastShowTime || Date.now() - this.lastShowTime > 1000) {
|
if (!this.lastShowTime || Date.now() - this.lastShowTime > 1000) {
|
||||||
@@ -79,6 +80,10 @@ export class WriteComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this.userInfoSub.unsubscribe();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 提交按钮的事件
|
// 提交按钮的事件
|
||||||
articleSubmit() {
|
articleSubmit() {
|
||||||
|
|||||||
Reference in New Issue
Block a user