ckeditor5-angular如何获取焦点?

import * as ClassicEditor from '@ckeditor/ckeditor5-build-classic';
@Component({
  selector: 'app-course-part',
  templateUrl: './course-part.component.html',
  styleUrls: ['./course-part.component.scss']
})
export class CoursePartComponent implements OnInit, AfterViewChecked, AfterViewInit {
  @ViewChild('createTitleRef', { static: false }) createTitleRef: HTMLInputElement;
  @ViewChild('contentRef', { static: false }) contentRefC: HTMLElement;
  @ViewChild('codeInputRef', { static: false }) codeInputRef: ElementRef;
  @ViewChild('ckeditorRef', { static: false }) ckeditorRef: any;
  @ViewChildren('h') h: QueryList<HTMLElement>;
  editorRef = null;
  Editor = ClassicEditor;
  config = { toolbar: ['heading', '|', 'bold', 'italic'], placeholder: '输入文本', startupFocus: true };
  showTitle = false; // 是否显示标题框
  title = '';
  code = '';
  text = '';
  image = '';
  showType;
  indexs = { parentIndex: 0, childIndex: 0 };
  nodeContent = [];
  mdIndex = 0; // 描点标识
  contentUpdate = true; // 内容更新标识
  activeType = 'a1';  // 当前选中部分
  isEditTitle = false;
  loading = false;
  constructor() {

  }


  ngOnInit() {
    if (localStorage.getItem('nodeContent')) {
      this.nodeContent = JSON.parse(localStorage.getItem('nodeContent'));
      this.mdIndex = this.nodeContent.length;
    }

  }

  ngAfterViewInit(): void {
    // this.contentRefC['nativeElement'].addEventListener('scroll', (e) => {
    //   this.setPartActive(e)
    // });
  }

  ngAfterViewChecked(): void {
    if (this.createTitleRef) {
      this.createTitleRef['nativeElement'].focus();
    }
    if (this.contentUpdate) {
      this.contentUpdate = false;
      this.setH1ScrollTop();
    }
    if (this.codeInputRef) {
      this.codeInputRef['nativeElement'].focus();
    }
    // console.log(new ClassicEditor().editing);
    // this.Editor.editing.view.focus()
    console.log(this.ckeditorRef);

  }

下面是html

<ckeditor #ckeditorRef (focus)="contentFocus($event)" (blur)="contentBlur($event)" style="width: 800px; margin:10px 0 10px 24px; display:block" [(ngModel)]="text" [editor]="Editor" [config]="config"></ckeditor>

需要如何获取焦点?下面两种方式都不行
**this.ckeditorRef.editing.view.focus()
this.Editor.editing.view.focus()**

阅读 1.3k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进