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