mobxjs / mobx-angular

The MobX connector for Angular.
MIT License
483 stars 59 forks source link

Compatibility with pipes #26

Closed gideoncatz closed 7 years ago

gideoncatz commented 7 years ago

Hi,

I was trying to pass an array to angular's standard slice pipe. That array is a part of a data store service which is injected into that particular component, and is defined with @observable decorator.

So when I try to run this array through the slice pipe, (passing the array, a start index and an end index) I get this:

Invalid argument '[object Object],[object Object],[object Object]' for pipe 'SlicePipe'

The pipe works properly if I remove the @observable decoration. Please check.


Update:

Strange. As part of code changes which I did later on, I'm now getting the same error even when the @observable decorator is not present.

Do you have an example of how to properly use arrays marked with @observable in conjunction with pipes?

Thanks, Gideon

adamkleingit commented 7 years ago

Hey, Can you paste the code of the SlicePipe?

Thanks

returnlytom commented 7 years ago

@gideoncatz Perhaps the pipe is expecting a JS Array instead of an Observable Array? https://mobx.js.org/refguide/array.html explains how mobx wraps the standard Array class

gideoncatz commented 7 years ago

Thanks for the link, @returnlytom ! Adding a .slice() before the pipe did the trick:

<li *ngFor="let name of dataStore.getNames().slice() | slice:0:2">{{name}}</li>