Knowledge Builders

what are feature modules in angular

by Rocky Cronin Published 2 years ago Updated 2 years ago
image

There are five types of feature modules in Angular current version:

  • Domain feature modules — Based on the application navigation. i.e. Product and Product features modules.
  • Routed feature modules — All Lazy loaded modules are routed modules.
  • Routing modules — Related with the routing and it’s functionality i.e. Routed guards.
  • Service feature modules — Utility related to...

Full Answer

What's the difference between an angular component and module?

Differences Between Component and Module in Angular Module. NgModule is one of the first basic structures you meet when coding an app with Angular, but it's also the most complex, because of different scopes. Component. A component controls a patch of the screen called a view. ... Tip: For those who want more detailed explanations, there is a great post on Toptal, check it out here.

What are angular features?

  • Routing – Angular can take care of routing which means moving from one view to another. ...
  • Angular supports testing, both Unit Testing, and Integration Testing.
  • It extends HTML by providing its own elements called directives. At a high level, directives are markers on a DOM element (such as an attribute, element name, and comment or ...

What are the key components of angular?

What are the key components of Angular?

  • Component: These are the basic building blocks of angular application to control HTML views.
  • Modules: An angular module is set of angular basic building blocks like component, directives, services etc. ...
  • Templates: This represent the views of an Angular application.

More items...

How to create AngularJS modules?

  • Create a new Angular Application: Using the following command, we can quickly create an angular app: ng new geeksforgeeks-solution
  • Create the main module: Go inside our project folder. ...
  • Import-module to module.ts file: We simply import our module into the app.module.ts file, so update this file as shown below:

image

What Is Feature Modules in Angular?

So, in Angular Framework, Feature Module is simply an Angular module with module related kinds of stuff and purpose. But the main difference is that is not the root module of the application. Feature module is just an additional typescript based class with the @NgModule decorator and registered metadata. Feature modules isolate the applications based on the functionality or business operation and it collaborates with the root modules or any other feature modules.

What is the purpose of feature modules?

The main purpose of the feature modules is to break down the functionality which focuses on any particular internal business operation or functionality that needs to be dedicated as a module so that we can achieve modularity in the application. With the help of feature modules, we also can restrict the responsibility of the root modules and help the root module to keep it thin and small.

What does lazy load mean in a module?

Lazy load of the feature modules on demand means when the user wants to access that module or related functionality then only that particular module will be loaded into the DOM.

What is lazy loading in Angular?

The lazy loading technique is not a new one introduced by the Angular Framework. It is a process or method to download the data on-demand, say , for example, Documents, JavaScript files, CSS, Images, and Videos in small pieces. This process or method normally performs the data loads operations in chunks instead of bigger pieces to improve the performance of the application.

How many different types of feature modules are there?

In general, we can define five different types of feature modules in an application – Domain, Routed, Routing, Service, and Widget. Each of these types of feature module concentrates and provides specific types of utilities.

Why is the feature module important?

With the help of the feature module, we can organize the code and structure in a much better way. It will always help us to decouple the non-related functionality and features.

Can you do everything with the root module?

Practically we can do everything with the root module, say app module in our case. Putting everything in the root module pollutes the root module. The feature module provides a set of functionality, flow, and forms focused on application needs.

What is feature module Angular?

A Feature Module in Angular is a module other than our main application root module that is decorated by @ngModule () decorator and hence share the same property configurations like application root module. You can also say it a custom module or an external module, but Feature Module is an Angular way of saying wherein we separate our features of our main application into a different module.

What is an Angular module?

Angular modules are independent block of distributable code. These can be exported as a library. For e.g. Angular provides us with BrowserModule, HttpModule, FormsModule etc. Similarly we can make our own Angular module which can be used in one or more application depending on the scope of functionality which we are building,

Is it easier to do Angular modules?

It is much easier to do with Angular Modules .

Can a module import other modules?

It can import other modules in its own module declara tion and use their components, directives and pipes.

What is feature module?

Feature modules are NgModules for the purpose of organizing code.

Why don't feature modules export?

Routed feature modules don’t export anything because their components never appear in the template of an external component.

What is the suffix for routing module?

The name of the routing module should parallel the name of its companion module, using the suffix "Routing". For example, FooModule in foo.module.ts has a routing module named FooRoutingModule in foo-routing.module.ts. If the companion module is the root AppModule, the AppRoutingModule adds router configuration to its imports with RouterModule.forRoot (routes). All other routing modules are children that import RouterModule.forChild (routes).

Which module should import service modules?

The root AppModule is the only module that should import service modules.

Do domain feature modules have providers?

Domain feature modules rarely have providers. When they do, the lifetime of the provided services should be the same as the lifetime of the module.

Why and how to structure Features in Modules in Angular

This might sound pretty basic, but I encounter these challenges over and over in customer projects and it’s still an ongoing discussion internally.

Prologue: Feature vs. Technical Project Structure

When building small apps and looking at common code samples in the internet a lot of devs (including myself) tend to come up with a project structure like this:

Why put a Feature into a Module?

Just grouping services and components into folders by feature doesn’t fully deliver on the above idea. Using a module to define a feature in Angular allows for isolation, portability and lazy loading. So we choose to group features in modules by default (no rule without exceptions…).

Example: Blocking Progress Indicator

A good sample for the mentioned benefits is a blocking progress indicator that overlays the current UI with a progress animation whenever a feature needs to block the UI from interaction e.g. to do an asynchronous operation.

Use Module in multiple modules

The BlockingProgressModule is made to be used across multiple components and it’s UI will be hosted in the main app module. We could just import the BlockingProgressModule into our AppModule and then go and inject the service into whatever child module we like.

Conclusion

Hope this explanation provides some context to those who struggle to structure and connect modules in Angular. There might not be a one fits all approach and we’re still discussing aspects of this internally. Please feel free to provide feedback.

What are the factors that affect Angular architecture?

One of the biggest factors that affect a solid Angular architecture is how we organize our features of the application.

What is the most important thing to do when building an Angular application?

Organizing features and modules is one of the most important things one can do when building an Angular application. If you don’t plan for this from start it can block you from using some Angular features, as well as it can make maintenance more difficult. We should also consider using core and shared modules, and these are directly recommended ...

What are the benefits of self-contained features?

They are in charge of the routing, services and components used in that feature.

Do all modules need to import dependencies?

When it comes to components, pipes and directives, every module should import its own dependencies disregarding if the same dependencies were imported in the root module or in any other feature module. In short, even when having multiple feature modules, each one of them needs to import the CommonModule.

Can we import feature module into simplified root module?

We can now import this feature module into our simplified root module.

image

How to Make A Feature Modulelink

  • Assuming you already have an application that you created with the Angular CLI, create a feature module using the CLI by entering the following command in the root project directory.Replace CustomerDashboardwith the name of your module.You can omit the "Module" suffix from the na…
See more on angular.io

Importing A Feature Modulelink

  • To incorporate the feature module into your app, you have to let the root module, app.module.ts, know about it.Notice the CustomerDashboardModule export at the bottom of customer-dashboard.module.ts.This exposes it so that other modules can get to it.To import it into the AppModule, add it to the imports in app.module.ts and to the importsarray: Now the AppModule …
See more on angular.io

Rendering A Feature Module's Component TemplateLink

  • When the CLI generated the CustomerDashboardComponent for the feature module, it included a template, customer-dashboard.component.html, with the following markup: To see this HTML in the AppComponent, you first have to export the CustomerDashboardComponent in the CustomerDashboardModule.In customer-dashboard.module.ts, just beneath the declarations arr…
See more on angular.io

More on Ngmoduleslink

  • You may also be interested in the following: 1. Lazy Loading Modules with the Angular Router 2. Providers 3. Types of Feature Modules
See more on angular.io

1.Angular

Url:https://angular.io/guide/feature-modules

35 hours ago  · A feature module is an organizational best practice, as opposed to a concept of the core Angular API. A feature module delivers a cohesive set of functionality focused on a …

2.Videos of What Are Feature Modules in Angular

Url:/videos/search?q=what+are+feature+modules+in+angular&qpvt=what+are+feature+modules+in+angular&FORM=VDRE

9 hours ago  · There are five general categories of feature modules which tend to fall into the following groups: Domain feature modules. Routed feature modules. Routing modules. …

3.Module and Feature Modules | A Complete Angular …

Url:https://witscad.com/course/complete-angular/chapter/module-and-feature-modules

32 hours ago What is an Angular Module? Adding Components, Pipes and Services to a Module. Creating a Feature Module. Directive Duplications. Lazy Loading a Module. Shared Modules and …

4.Angular - Types of Feature Modules - w3resource

Url:https://www.w3resource.com/angular/types-of-feature-modules.php

27 hours ago A small Angular application can have one as well as many feature NgModules. A feature module is a custom module. The root NgModule can include child NgModules in a hierarchy …

5.Why and how to structure Features in Modules in Angular

Url:https://medium.com/medialesson/why-and-how-to-structure-features-in-modules-in-angular-d5602c6436be

23 hours ago 5 rows · Domain feature modules deliver a user experience dedicated to a particular application domain ...

6.Angular: Organizing Features and Modules | by Joao …

Url:https://medium.com/swlh/angular-organizing-features-and-modules-e582611a720e

18 hours ago

7.Creating a Feature Module - Rangle.io : Angular Training

Url:https://angular-training-guide.rangle.io/modules/feature-modules

4 hours ago

8.What are Modules in Angular - TutorialsBuddy

Url:https://www.tutorialsbuddy.com/modules-in-angular

23 hours ago

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9