Sharing Top Content from the Angular-sphere.

Working With Angular Modules in NativeScript Apps

Working With Angular Modules in #NativeScript Apps  #mobile

  • NativeScriptModule – provides services that are essential to run a NativeScript app.
  • Since each lazy module has it’s own dependency injector, we’ll end up with a bunch of renderers if we import the NativeScriptModule in each lazy module.
  • You should import in every feature and lazy-loaded module.
  • The best practice: only import (or ) in modules that: – – NativeScriptFormsModule – provides you with two-way binding using .
  • The best practice: it should be imported in the and once per each lazily-loaded bundle, which contains components that either: – – It is also important to understand about Sharing Modules, which allow you to prepackage commonly used directives and pipes.

Just like all mushrooms are edible, except some only once in your lifetime, so are the NgModules – some you can import everywhere, and some only once per app.

Do you know, which modules you should import everywhere and which only once?

Do you know what happens every time you add NativeScriptModule to each of your @NgModule?

Just like all mushrooms are edible, except some only once in your lifetime, so are the NgModules – some you can import everywhere, and some only once per app.

Do you know, which modules you should import everywhere and which only once?

Do you know what happens every time you add to each of your ?

Let me help you.

NativeScriptModule and NativeScriptAnimationsModule should only ever be imported in your . If you import them multiple times then the performance of your app might suffer.

NativeScriptModule – provides services that are essential to run a NativeScript app. Most importantly it provides the renderer. Since each lazy module has it’s own dependency injector, we’ll end up with a bunch of renderers if we import the NativeScriptModule in each lazy module. This would additionally cause a lot of problems with Angular – starts by initialising crucial animation elements , , , , but most importantly it creates a wrapper around the renderer.

To help you get it right, we are going to add some changes to these modules, so that when you import either of them more than once you will see an error message like this:

Some modules can be (or even should be) imported with every feature and lazy-loaded module.

Working With Angular Modules in NativeScript Apps