What is @angular/compiler?
The @angular/compiler package is a core part of the Angular framework that is responsible for compiling Angular templates into JavaScript code that can be executed by the browser. It takes the templates and annotations provided in Angular components and generates code that represents the structure and behavior of the application.
What are @angular/compiler's main functionalities?
Template Compilation
This feature allows you to compile Angular components and modules dynamically at runtime. The code sample demonstrates how to use the JIT compiler to compile a module and its components asynchronously.
import { Compiler, COMPILER_OPTIONS, CompilerFactory } from '@angular/core';
import { JitCompilerFactory } from '@angular/platform-browser-dynamic';
// Get a reference to the JIT compiler factory
const compilerFactory: CompilerFactory = platformBrowserDynamic().injector.get(CompilerFactory);
const compiler = compilerFactory.createCompiler();
// Compile a component dynamically
compiler.compileModuleAndAllComponentsAsync(DynamicModule)
.then(compiled => {
const moduleRef = compiled.ngModuleFactory.create(this.injector);
const componentFactory = compiled.componentFactories[0];
this.container.createComponent(componentFactory);
});
AOT Compilation
Ahead-of-Time (AOT) compilation converts Angular HTML and TypeScript code into efficient JavaScript code during the build process, before the browser downloads and runs the code. This code sample shows how to bootstrap an Angular application using the AOT-compiled module factory.
import { enableProdMode } from '@angular/core';
import { platformBrowser } from '@angular/platform-browser';
import { AppModuleNgFactory } from './app/app.module.ngfactory';
enableProdMode();
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);
Other packages similar to @angular/compiler
babel
Babel is a JavaScript compiler that converts ECMAScript 2015+ code into a backwards-compatible version of JavaScript that can be run by older JavaScript engines. Babel is similar to @angular/compiler in that it performs code transformation, but it is not specific to Angular and does not compile Angular templates.
typescript
TypeScript is a superset of JavaScript that compiles to plain JavaScript. It is similar to @angular/compiler in that it performs a compilation step, but TypeScript focuses on type-checking and converting TypeScript code to JavaScript, rather than compiling framework-specific templates.
vue-template-compiler
The vue-template-compiler package is used to compile Vue.js templates into render functions. It is similar to @angular/compiler as both are used for compiling framework-specific templates, but they target different frameworks (Vue.js vs Angular).
19.0.1 (2024-11-26)
compiler-cli
| Commit | Type | Description |
| -- | -- | -- |
| fb1fa8b0fc | fix | more accurate diagnostics for host binding parser errors (#58870) |
core
| Commit | Type | Description |
| -- | -- | -- |
| 502ee0e722 | fix | correctly clear template HMR internal renderer cache (#58724) |
| 99715104a1 | fix | correctly perform lazy routes migration for components with additional decorators (#58796) |
| 118803035f | fix | Ensure _tick is always run within the TracingSnapshot. (#58881) |
| 08b9452f01 | fix | Ensure resource sets an error (#58855) |
| 84f45ea3ff | fix | make component id generation more stable between client and server builds (#58813) |
| d3491c7cee | fix | Prevents race condition of cleanup for incremental hydration (#58722) |
forms
| Commit | Type | Description |
| -- | -- | -- |
| 4dfe5b6cef | fix | work around TypeScript 5.7 issue (#58731) |
language-service
| Commit | Type | Description |
| -- | -- | -- |
| a983865bff | fix | add fix for individual unused imports (#58719) |
| e6e7a4e22b | fix | allow fixes to run without template info (#58719) |
migrations
| Commit | Type | Description |
| -- | -- | -- |
| 5ce10264a4 | fix | fix provide-initializer migration when using useFactory (#58518) |
| d4f5c85f60 | fix | handle parameters with initializers in inject migration (#58769) |
| a6d2d2dc10 | fix | Mark hoisted properties as removed in inject migration (#58804) |
<!-- CHANGELOG SPLIT MARKER -->
<a name="19.0.0"></a>