我试图从一个函数调用一个服务,但我在控制台收到此错误:呼叫服务
无法读取的未定义的属性“TestMethod的”
这是我的代码:
app.component.ts:
constructor(public _service: BackendFileCodeService){ } public editor; EditorCreated(quill) { const toolbar = quill.getModule('toolbar'); this.editor = quill; // console.log(quill) toolbar.addHandler('image', this.imageHandler); } imageHandler(value) { // document.querySelector('input.ql-image[type=file]').addEventListener('click',() => { // console.log('Hello'); // }); const ImageInput = document.createElement('input'); ImageInput.setAttribute('type', 'file'); ImageInput.setAttribute('accept', 'image/png, image/gif, image/jpeg, image/bmp, image/x-icon'); ImageInput.classList.add('ql-image'); ImageInput.click(); ImageInput.addEventListener('change',() => { const file = ImageInput.files[0]; if (ImageInput.files != null && ImageInput.files[0] != null) { this._service.TestMethod('Hello'); } }); }
BackendFileCodeService:
import { Injectable } from '@angular/core'; @Injectable() export class BackendFileCodeService { constructor() { } TestMethod(test){ return test; } }
我想打电话叫imageHandler函数内部的服务特别是在
ImageInput.addEventListener
但我在提到错误时,我试图从imageH外部调用服务安德勒功能和每一个这样的预期工作。
注意:该服务是控制台日志“hello”作为测试。