angular 2 - Typescript and modules (lazy/conditional module loading, external/internal TS modules, referencing files by path/name etc)

457 views
Skip to first unread message

Olivier Clément

unread,
Jan 4, 2016, 2:42:25 PM1/4/16
to AngularJS
We're starting a project with NG2 using Typescript

The architect is not a fan of having to do imports by referencing files by `path/name` (the ES6 way or otherwise) and would rather reference modules by namespace/name

Before Typescript starts implementing ES6-style modules, when you are targeting ES5 from TS, it basically creates namespaces with closures. Since NG1 doesn't natively support lazyloading of (angular) modules it's not really a problem since the app is to be bundled anyways. With NG2 (correct me if I'm wrong) supporting lazy loading, and I feel using ES6 modules would be the way to go; It's a long shot, but would there be a way to still reference modules by name instead of filename? What would be the pros/cons you'd see?

Assuming it's not, and he decides that we should not use Es6 modules and stay with TS internal modules (now called namespace I think?), how bad a choice would it be and why? Would it still be possible to achieve lazy loading of module if the need arise?

If he/we decide to go the ES6-style module route; I suppose we absolutely need some kind of module loader such as System/JSPM or Webpack or even Browserify, am I right?
Any other option out there? (I'm asking about strategies, not tools such as requireJS)

And last question, which is closer to lazy loading with NG2:
Would it be possible to load a module conditionally based on, say, a user's role? Say the user only has access to the application's A, B, D sections, only load those modules that defines these sections, and not C which the user don't have access to, saving on bandwidth and what not

I realize there are more than one question here but since they are intimately related, I figured I'd make a single post about it

Thank you!

O.

Olivier Clément

unread,
Jan 5, 2016, 9:45:08 AM1/5/16
to AngularJS
Bump - No one can shed even just a little bit of light on this?
Reply all
Reply to author
Forward
0 new messages