如何解决AngularJS和Javascript类::错误ReferenceError:未定义<oblect>
我正在尝试在AngularJS [v 10]打字稿对象中使用自定义Java Script类。但无法使用与之相同的错误并得到
错误ReferenceError:未定义
这是我的代码
JavaScript simple-image.js文件
export class SimpleImage {
constructor() {
}
render(){
return document.createElement('input');
}
}
将文件注册到angular.json
"scripts": [
"src/assets/simple-image.js"
]
使用app.component.ts中的JavaScript文件
import { Component } from '@angular/core';
import EditorJs from '@editorjs/editorjs';
import Header from '@editorjs/header';
declare var SimpleImage:any;
@Component({
selector: 'app-root',templateUrl: './app.component.html',styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'editor-example';
public editor: any;
ngOnInit(): void {
this.editor = new EditorJs({
holderId: "contentpart",autofocus: true,tools: {
header: {
class: Header,inlineToolbar: ['link'],config: {
placeholder: 'Header'
}
},image: {
class: new SimpleImage(),}
},/**
* onReady callback
*/
onReady: () => {
alert('Editor.js is ready to work!')
}
}),this.editor.isReady
.then(() => {
console.log('Editor.js is ready to work!')
/** Do anything you need after editor initialization */
})
.catch((reason) => {
console.log(`Editor.js initialization failed because of ${reason}`)
});
}
}
我在控制台中遇到以下错误
ERROR ReferenceError: SimpleImage is not defined
ngOnInit app.component.ts:38
Angular 24
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。