我正在尝试在 AngularJS [v 10] typescript 对象中使用自定义 Java Script 类。但无法使用相同的内容并出现错误
错误参考错误:未定义
这是我的代码
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(),
inlineToolbar: ['link'],
}
},
/**
* 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