Abort request in 7.0?
adrianmarinica opened this issue · 2 comments
adrianmarinica commented
What would be the recommended way to abort a request with the 7.0 functionality? I found an abort
method in the IResourceHandlerResponse
interface, but I can't seem to find the necessary objects to use it. The only object of this type is the result of the handle
method in the ResourceHandler
object, but this handle
method requires an IResourceRequest
object that I have no idea where to get.
Is this still a supported functionality? Thanks!
troyanskiy commented
Hello @adrianmarinica
It is still supported, but I would recommend to use observable method and unsubscribe if you need to cancel the request.
ex:
@Injectable()
@ResourceParams({
.... your options
})
export class MyResource extends Resource {
@ResourceAction({
.... your options
})
someMethod$: IResourceMethodObservable<any, any>;
}
// component
export class MyComponent implements OnInit, OnDestroy {
data: any = null;
private subscription: Subscription | null = null;
constructor(private myResource: MyResource) {}
ngOnInit() {
this.subscription = this.myResource.someMethod$.subscribe(data => {
this.data = data;
this.subscription = null;
})
}
ngOnDestroy() {
if (this.subscription) {
this.subscription.unsubscribe();
this.subscription = null;
}
}
}
adrianmarinica commented
Thanks for the help and for the code sample!