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()**
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论