mobxjs / mobx-angular

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

MobxAutorunDirective throws a TypeError when used with a Pipe #16

Closed returnlytom closed 7 years ago

returnlytom commented 7 years ago

First of all, thanks for this lib, it's been very useful in refactoring a spaghetti mess of state manipulation into something easier to reason about and maintain.

When using mobx + ng2-mobx, found a reproducible issue when using a Pipe. Here's an example stack trace:

TypeError: Cannot read property 'transform' of undefined
    at View_App1.createInternal (/AppModule/App/component.ngfactory.js:32)
    at View_App1.AppView.create (VM329 core.umd.js:11878)
    at View_App1.DebugAppView.create (VM329 core.umd.js:12282)
    at TemplateRef_.createEmbeddedView (VM329 core.umd.js:8897)
    at ViewContainerRef_.createEmbeddedView (VM329 core.umd.js:9117)
    at new MobxAutorunDirective (VM337 ng2-mobx.umd.js:289)
    at new Wrapper_MobxAutorunDirective (/Ng2MobxModule/MobxAutorunDirective/wrapper.ngfactory.js:7)
    at CompiledTemplate.proxyViewClass.View_App0.createInternal (/AppModule/App/component.ngfactory.js:93)
    at CompiledTemplate.proxyViewClass.AppView.create (VM329 core.umd.js:11878)
    at CompiledTemplate.proxyViewClass.DebugAppView.create (VM329 core.umd.js:12282)
    at CompiledTemplate.proxyViewClass.View_App_Host0.createInternal (/AppModule/App/host.ngfactory.js:16)
    at CompiledTemplate.proxyViewClass.AppView.createHostView (VM329 core.umd.js:11891)
    at CompiledTemplate.proxyViewClass.DebugAppView.createHostView (VM329 core.umd.js:12299)
    at ComponentFactory.create (VM329 core.umd.js:7288)
    at ApplicationRef_.bootstrap (VM329 core.umd.js:8257)

Here is a link to a plunk with the issue (check out the console):

http://plnkr.co/edit/dUFlmCZN80gaodTJt31m?p=preview

And, by accident I discovered this workaround as a temporary fix (wrap with an *ngIf="true"):

http://plnkr.co/edit/sISR7m1pTmgtwRIyvnMB?p=preview

adamkleingit commented 7 years ago

Hey, I created the embedded view in the c'tor instead of ngOnInit. Fixed & Published 1.2.7:

http://plnkr.co/edit/UbURaa2PyzhWjW37vssL?p=preview