Angular 2 dependency injection error on NgFor in d

2019-07-09 05:00发布

I've dynamically created an Angular 2 component using DynamicComponentLoader.loadAsRoot(), and am trying to give it a useful template (involving NgFor), but this is somehow yielding me a 'DI exception' dependency injection error.

I had already injected NgFor itself though, so specifically now it gave me a No provider for IterableDiffers! (NgFor -> IterableDiffers). So I injected that, which got me to a No provider for Array! (NgFor -> IterableDiffers -> Array). At this point I got stumped; Array is a base type rather than something part of Angular, and somehow trying to similarly inject it did not work (error: Array is a generic; must specificy some sub-type). I'm confused but I'd be surprised if basic types suddenly required injection.

I made a Plunker to recreate my issue here. Interestingly on Plunker the DI exception turned out as No provider for e! (e -> e) instead. Not sure why the difference, but the principle issue would seem similar... though e gives me even less useful info to go by than Array. :(

How might I prevent such exceptions here?

0条回答
登录 后发表回答