Angular proposal would make NgModules optional

The Angular development team considers a shift toward a simpler reuse model to improve the developer experience.

Angular proposal would make NgModules optional
Thinkstock

The developers of Angular, the popular TypeScript-based web framework, are considering making NgModules optional. The goal is to shift Angular toward a simpler reuse model to improve the developer experience.

An RFC (request for comment) proposal being floated on GitHub, titled “Standalone components, directives and pipes — making Angular’s NGModules optional,” seeks to validate the intended design with the community, solicit feedback, and enable experimentation via a non-production-ready prototype. The RFC was posted October 8 and is slated to close no sooner than November 8.

A core Angular concept, NgModules are containers of functionality used to manage dependencies in the framework. When a component needs to make use of another component, directive, pipe, or provider, the dependency is not directly referenced. Instead, an NgModule is imported, containing exported components, directives, and pipes, along with configured providers. As a result, developers must create an NgModule to bootstrap even the simplest “Hello, World” application.

Having Angular conceptually centered around NgModule negatively impacts the developer experience, the RFC argues. The RFC cites multiple reasons:

  • Authoring of components is more involved than coding a class or template.
  • APIs around loading and rendering are unnecessarily complex and easy to misuse.
  • Reading component code is not sufficient to understand component behavior.
  • Angular tools must deal with “implicit” dependencies of components on their NgModule context.

The RFC calls for moving Angular in a direction where components, directives, and pipes play a more central role, are self-contained, and can be safely imported and used directly. The plan would simplify the “mental model” of Angular, make new APIs possible for using components and directives (such as an API for fine-grained lazy loading), and improve the ability of Angular tools to efficiently process code. Thus Angular would be simpler to use, easier to reason about, less verbose, and faster to compile.

The concept of the NgModule would not be removed from Angular, but would be made optional for typical development tasks. At some point, the Angular development team could consider removing NgModules altogether. Meanwhile, the proposal stresses that NgModules are neither going away nor being deprecated. Developers would continue to be able to create them and use them.

Angular itself continues to move forward while the development team ponders the NgModule change. Angular 13 is due next week, completing the transition to the Ivy compilation and rendering engine. Angular 12, published on June 24, also focused on Ivy.

Copyright © 2021 IDG Communications, Inc.