I want to use a service object in callback method. I get undefined error when I use the service in callback method. How can I solve it?
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
}
}