0
我想在回调方法中使用服务对象。当我在回调方法中使用服务时出现未定义的错误。我该如何解决它?Angular4我怎样才能调用封闭的服务方法
send.component.ts
import { Component } from '@angular/core';
import { ExampleService } from '../../services/example.service';
@Component({
selector: 'example',
templateUrl: './send.component.html',
styleUrls: ['./send.component.css']
})
export class SendComponent {
public exampleService = null
constructor(private service: ExampleService) {
this.exampleService = service
}
submit() {
function postSendTransactionCallback(result) {
console.log(this.exampleService); // exampleService is undefined
}
this.exampleService.postSendTransaction(this.data, postSendTransactionCallback); // This is no problem
}
}
谢谢。你救了我。我会在2分钟内接受你的回答。 – zono