troyanskiy/ngx-resource

Inconsistency between `$observable` and `$observable.toPromise()`

marshall007 opened this issue · 4 comments

I would expect the following two examples to be equivalent, but it seems that when using toPromise, the result is still a wrapped ResourceResult:

resource.get({ id: '123' }).$observable.subscribe(
  (value) => this.data = value // T
)

resource.get({ id: '123' }).$observable.toPromise().then(
  (value) => this.data = value // ResourceResult<T>
)

Somewhat related, there appears to be a possible race condition when using resource.save(...) which prevents $cleanData(...) from being called before the request is sent.

For me both are same

this._u.testGet()
      .$observable
      .subscribe((data: any) => {
        console.log('Data 1', data);
      });

    this._u.testGet()
      .$observable
      .toPromise()
      .then((data: any) => {
        console.log('Data 2', data);
      });

image

Could you please provide plunker example to debug the Inconsistency between $observable and $observable.toPromise()

Thanks

@troyanskiy not sure what was going on before, but I can't reproduce this again. Also updating to v3.2.4 seems to have fixed $ properties being included in POST requests.