fix: 空值异常

This commit is contained in:
禾几海
2020-10-10 00:25:22 +08:00
parent b63697f717
commit a4fa38deee
3 changed files with 6 additions and 10 deletions

View File

@@ -73,9 +73,8 @@ export class ArticleComponent implements OnInit {
after: () => { after: () => {
// 处理锚点 // 处理锚点
const tocList: HTMLCollection = this.divElement.nativeElement const tocList: HTMLCollection = this.divElement.nativeElement
.getElementsByClassName('vditor-toc')[0] .getElementsByClassName('vditor-toc')[0]?.getElementsByTagName(`a`);
.getElementsByTagName(`a`); for (let i = 0; i < tocList?.length; i++) {
for (let i = 0; i < tocList.length; i++) {
const linkValue = tocList.item(i).getAttribute('href'); const linkValue = tocList.item(i).getAttribute('href');
tocList.item(i).setAttribute('href', window.location.pathname + linkValue); tocList.item(i).setAttribute('href', window.location.pathname + linkValue);
} }

View File

@@ -4,10 +4,6 @@
<button nz-button nzType="primary" id="submit" (click)="articleSubmit()">提交</button> <button nz-button nzType="primary" id="submit" (click)="articleSubmit()">提交</button>
</div> </div>
<div id="vditor"></div> <div id="vditor"></div>
<!-- <div id="md" appEditorMd [editormdConfig]="conf" (editorChange)="syncModel($event)">-->
<!-- <textarea style="display: block;" [(ngModel)]="article.mdContent"></textarea>-->
<!-- </div>-->
</div> </div>
<nz-modal [(nzVisible)]="modalVisible" [nzTitle]="title" [nzContent]="content" [nzFooter]="null" <nz-modal [(nzVisible)]="modalVisible" [nzTitle]="title" [nzContent]="content" [nzFooter]="null"

View File

@@ -3,10 +3,11 @@ import {CommonModule} from '@angular/common';
import {WriteComponent} from './write.component'; import {WriteComponent} from './write.component';
import {Route, RouterModule} from '@angular/router'; import {Route, RouterModule} from '@angular/router';
import {FormsModule, ReactiveFormsModule} from '@angular/forms'; import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {EditorMdDirective} from './editor-md/editor-md.directive';
import {PublishFormComponent} from './components/publish-form/publish-form.component'; import {PublishFormComponent} from './components/publish-form/publish-form.component';
import { import {
NzButtonModule, NzCardModule, NzDividerModule, NzButtonModule,
NzCardModule,
NzDividerModule,
NzFormModule, NzFormModule,
NzIconModule, NzIconModule,
NzInputModule, NzInputModule,
@@ -23,7 +24,7 @@ const routes: Route[] = [
@NgModule({ @NgModule({
declarations: [WriteComponent, EditorMdDirective, PublishFormComponent], declarations: [WriteComponent, PublishFormComponent],
imports: [ imports: [
CommonModule, CommonModule,
RouterModule.forChild(routes), RouterModule.forChild(routes),