Meta tags:
description= The web development framework for building modern apps.;
author= Angular Team;
keywords= Angular framework, TypeScript, web development, hydration, Signals, standalone components, accessibility, performance;
Headings (most frequently used words):
aot, compilation, phase, code, type, community, syntax, and, functions, ahead, of, time, on, this, page, choosing, compiler, how, works, analysis, generation, template, checking, social, media, resources, translations, phases, metadata, restrictions, configuring, expression, limitations, folding, public, or, protected, symbols, supported, classes, static, method, calls, narrowing, non, null, assertion, operator, foldable,
Text of the page (most frequently used words):
the (208), angular (57), compiler (50), and (49), metadata (41), #template (37), person (29), this (27), component (27), aot (26), address (22), that (22), for (22), can (22), expression (20), type (19), code (18), hero (18), class (17), typescript (17), error (17), collector (17), application (16), you (15), yes (15), with (14), phase (14), literal (14), div (14), only (13), file (13), errors (13), new (13), syntax (13), json (13), are (12), build (12), example (11), foldable (11), compilation (11), when (10), mycomponent (9), null (9), operator (9), following (9), see (9), html (9), templates (9), your (9), name (8), selector (8), checking (8), object (8), typical (8), supported (8), reference (8), time (8), cli (8), ngif (7), non (7), binding (7), input (7), options (7), how (7), export (7), javascript (7), browser (7), span (6), street (6), value (6), configuration (6), expressions (6), array (6), google (5), there (5), using (5), use (5), does (5), uses (5), option (5), string (5), not (5), property (5), default (5), helpful (5), before (5), static (5), declarations (5), function (5), supports (5), functions (5), calls (5), decorators (5), create (5), exported (5), symbols (5), libraries (5), files (5), true (5), ahead (5), developer (4), used (4), set (4), undefined (4), information (4), same (4), reported (4), validation (4), methods (4), wrapinarray (4), call (4), definition (4), because (4), subset (4), return (4), however (4), instances (4), details (4), classes (4), data (4), must (4), public (4), protected (4), best (4), detects (4), required (4), app (4), process (4), during (4), applications (4), compile (4), components (4), v22 (3), style (3), below (3), assertion (3), might (3), constraint (3), always (3), some (3), possibly (3), more (3), allows (3), enabled (3), location (3), contains (3), writes (3), produces (3), consider (3), within (3), they (3), runtime (3), macros (3), source (3), core (3), later (3), generate (3), bound (3), cannot (3), outputs (3), violation (3), interpret (3), generation (3), substitutions (3), local (3), index (3), its (3), const (3), constant (3), into (3), evaluate (3), them (3), folding (3), than (3), building (3), needs (3), instance (3), apps (3), compiles (3), client (3), rendering (3), schematics (3), updated (3), licensed (2), under (2), community (2), report (2), youtube (2), setdata (2), lives (2), shown (2), properties (2), way (2), but (2), narrowing (2), custom (2), directives (2), never (2), above (2), interpolation (2), initialized (2), message (2), node (2), attribute (2), such (2), synthetic (2), contents (2), instead (2), templateurl (2), addresss (2), strict (2), controlled (2), angularcompileroptions (2), stricttemplates (2), one (2), any (2), validate (2), two (2), help (2), these (2), ngmodules (2), typicalmodule (2), ngmodule (2), had (2), written (2), method (2), module (2), from (2), creation (2), long (2), particular (2), decorated (2), members (2), make (2), private (2), understands (2), all (2), forms (2), attempt (2), collects (2), represents (2), records (2), resolve (2), ast (2), parentheses (2), conditional (2), binary (2), prefix (2), boolean (2), number (2), identity (2), target (2), access (2), spread (2), describes (2), which (2), fold (2), title (2), reduces (2), step (2), interprets (2), references (2), result (2), collection (2), rather (2), limited (2), strictmetadataemit (2), want (2), immediately (2), reports (2), cake (2), pie (2), better (2), ingredients (2), flour (2), first (2), analysis (2), available (2), conform (2), additional (2), phases (2), extracts (2), factory (2), dependency (2), someservice (2), constructor (2), specify (2), serving (2), run (2), serve (2), jit (2), side (2), fewer (2), injection (2), security (2), download (2), compiled (2), requests (2), downloads (2), faster (2), reasons (2), guide (2), tools (2), end (2), testing (2), workers (2), service (2), animations (2), release (2), server (2), setup (2), docs (2), menu (2), super, powered, 2010, 2026, documentation, built, sha, ff0068a, mit, license, 正體中文版, 简体中文版, 日本語版, 한국어, русский, türkçe, oʻzbekcha, français, español, azərbaycanca, translations, roadmap, press, kit, resources, experts, devlibrary, issues, conduct, contribute, stack, overflow, github, discord, bluesky, formerly, twitter, blog, social, media, recommended, include, should, sparingly, refactoring, break, together, implying, convenient, describe, suppressed, suppress, inconvenient, ensures, interpolated, about, improving, infer, will, directive, narrow, unions, avoid, modify, emit, well, checker, supplied, control, detailed, strictnullchecks, beginning, text, generated, holds, disk, line, column, numbers, relative, annotation, case, referenced, did, mean, exist, messages, detected, similar, against, project, most, features, ability, check, catch, cause, crashes, exports, macro, declare, root, child, routes, review, simplify, complex, forchild, forroot, routermodule, treats, usage, like, returns, conforms, restrictive, accepts, single, statement, form, injectiontoken, action, certain, represent, valid, refuse, also, may, reject, correct, violate, rules, semantics, syntactically, makes, understand, job, condition, both, left, right, operand, table, equivalent, folded, take, further, including, another, longer, therefore, nothing, trouble, output, could, refer, isn, lining, effect, effectively, removing, let, var, replace, called, reduced, manner, record, original, have, ensure, clean, practice, own, produce, ngc, unsupported, piece, 14153265, multiplier, times, slice, oven, bake, apples, cherries, sugar, cherry, apple, mincemeat, false, define, objects, limitations, format, interfaces, schema, think, diagram, overall, structure, decorator, represented, abstract, tree, analytic, work, emits, analyzes, recorded, per, provide, controls, complete, list, configuring, commonly, occur, requirements, described, fully, understanding, resolving, problems, guidelines, instructions, preparing, writing, friendly, after, limit, write, general, constraints, restrictions, collected, performs, throws, restriction, staticreflector, representation, three, generates, visual, element, injected, once, inject, typicaldata, tell, display, parts, supposed, manage, explicitly, implicitly, tells, construct, interact, works, command, locally, commands, depends, specified, starting, was, until, just, offers, ways, choosing, back, top, arrow_upward_alt, page, served, read, risky, evaluation, opportunities, attacks, users, detect, earlier, need, already, roughly, half, itself, omitting, dramatically, payload, smaller, framework, size, external, css, sheets, eliminating, separate, ajax, those, inlines, asynchronous, pre, version, loads, executable, render, without, waiting, here, angularconnect, 2019, watch, alex, rickabaugh, explain, explains, apply, efficiently, converts, efficient, runs, compiling, provides, consists, mainly, their, provided, understood, directly, require, authoring, generating, builders, environments, migrating, system, deployment, development, overview, arrow_back, material, cdk, player, pay, maps, fire, tailwind, pipeline, web, pwas, rxjs, legacy, extended, ecosystem, v21, events, keeping, date, performance, unhandled, accessibility, practices, language, devtools, webmcp, design, patterns, tutor, mcp, agent, skills, llm, prompts, ide, get, started, drag, drop, internationalization, aria, hybrid, http, routing, signals, depth, guides, start, coding, essentials, installation, what, introduction, more_horiz, playground, tutorials, close, skip, main, content,
Text of the page (random words):
erts your angular html and typescript code into efficient javascript code during the build phase before the browser downloads and runs that code compiling your application during the build process provides a faster rendering in the browser this guide explains how to specify metadata and apply available compiler options to compile your applications efficiently using the aot compiler helpful watch alex rickabaugh explain the angular compiler at angularconnect 2019 here are some reasons you might want to use aot reasons details faster rendering with aot the browser downloads a pre compiled version of the application the browser loads executable code so it can render the application immediately without waiting to compile the application first fewer asynchronous requests the compiler inlines external html templates and css style sheets within the application javascript eliminating separate ajax requests for those source files smaller angular framework download size there s no need to download the angular compiler if the application is already compiled the compiler is roughly half of angular itself so omitting it dramatically reduces the application payload detect template errors earlier the aot compiler detects and reports template binding errors during the build step before users can see them better security aot compiles html templates and components into javascript files long before they are served to the client with no templates to read and no risky client side html or javascript evaluation there are fewer opportunities for injection attacks on this page arrow_upward_alt back to the top choosing a compiler angular offers two ways to compile your application angular compile details just in time jit compiles your application in the browser at runtime this was the default until angular 8 ahead of time aot compiles your application and libraries at build time this is the default starting in angular 9 when you run the ng build build only or ng serve build and serve locally cli commands the type of compilation jit or aot depends on the value of the aot property in your build configuration specified in angular json by default aot is set to true for new cli applications see the cli command reference and building and serving angular apps for more information how aot works the angular aot compiler extracts metadata to interpret the parts of the application that angular is supposed to manage you can specify the metadata explicitly in decorators such as component or implicitly in the constructor declarations of the decorated classes the metadata tells angular how to construct instances of your application classes and interact with them at runtime in the following example the component metadata object and the class constructor tell angular how to create and display an instance of typical component selector app typical template div a typical component for data name div export class typical data input required typicaldata private someservice inject someservice the angular compiler extracts the metadata once and generates a factory for typical when it needs to create a typical instance angular calls the factory which produces a new visual element bound to a new instance of the component class with its injected dependency compilation phases there are three phases of aot compilation phase details 1 code analysis in this phase the typescript compiler and aot collector create a representation of the source the collector does not attempt to interpret the metadata it collects it represents the metadata as best it can and records errors when it detects a metadata syntax violation 2 code generation in this phase the compiler s staticreflector interprets the metadata collected in phase 1 performs additional validation of the metadata and throws an error if it detects a metadata restriction violation 3 template type checking in this phase the angular template compiler uses the typescript compiler to validate the binding expressions in templates strict checking in this phase is enabled by default and controlled by the stricttemplates configuration option see angular compiler options metadata restrictions you write metadata in a subset of typescript that must conform to the following general constraints limit expression syntax to the supported subset of javascript only reference exported symbols after code folding only call functions supported by the compiler input outputs and data bound class members must be public or protected for additional guidelines and instructions on preparing an application for aot compilation see angular writing aot friendly applications helpful errors in aot compilation commonly occur because of metadata that does not conform to the compiler s requirements as described more fully below for help in understanding and resolving these problems see aot metadata errors configuring aot compilation you can provide options in the typescript configuration file that controls the compilation process see angular compiler options for a complete list of available options phase 1 code analysis the typescript compiler does some of the analytic work of the first phase it emits the d ts type definition files with type information that the aot compiler needs to generate application code at the same time the aot collector analyzes the metadata recorded in the angular decorators and outputs metadata information in metadata json files one per d ts file you can think of metadata json as a diagram of the overall structure of a decorator s metadata represented as an abstract syntax tree ast helpful angular s schema ts describes the json format as a collection of typescript interfaces expression syntax limitations the aot collector only understands a subset of javascript define metadata objects with the following limited syntax syntax example literal object cherry true apple true mincemeat false literal array cherries flour sugar spread in literal array apples flour calls bake ingredients new new oven property access pie slice array index ingredients 0 identity reference component a template string pie is multiplier times better than cake literal string pi literal number 3 14153265 literal boolean true literal null null supported prefix operator cake supported binary operator a b conditional operator a b c parentheses a b if an expression uses unsupported syntax the collector writes an error node to the metadata json file the compiler later reports the error if it needs that piece of metadata to generate the application code helpful if you want ngc to report syntax errors immediately rather than produce a metadata json file with errors set the strictmetadataemit option in the typescript configuration file angularcompileroptions strictmetadataemit true angular libraries have this option to ensure that all angular metadata json files are clean and it is a best practice to do the same when building your own libraries code folding the compiler can only resolve references to exported symbols the collector however can evaluate an expression during collection and record the result in the metadata json rather than the original expression this allows you to make limited use of non exported symbols within expressions for example the collector can evaluate the expression 1 2 3 4 and replace it with the result 10 this process is called folding an expression that can be reduced in this manner is foldable the collector can evaluate references to module local const declarations and initialized var and let declarations effectively removing them from the metadata json file consider the following component definition const template div hero name div component selector app hero template template export class hero hero input required hero the compiler could not refer to the template constant because it isn t exported the collector however can fold the template constant into the metadata definition by in lining its contents the effect is the same as if you had written component selector app hero template div hero name div export class hero hero input required hero there is no longer a reference to template and therefore nothing to trouble the compiler when it later interprets the collector s output in metadata json you can take this example a step further by including the template constant in another expression const template div hero name div component selector app hero template template div hero title div export class hero hero input required hero the collector reduces this expression to its equivalent folded string div hero name div div hero title div foldable syntax the following table describes which expressions the collector can and cannot fold syntax foldable literal object yes literal array yes spread in literal array no calls no new no property access yes if target is foldable array index yes if target and index are foldable identity reference yes if it is a reference to a local a template with no substitutions yes a template with substitutions yes if the substitutions are foldable literal string yes literal number yes literal boolean yes literal null yes supported prefix operator yes if operand is foldable supported binary operator yes if both left and right are foldable conditional operator yes if condition is foldable parentheses yes if the expression is foldable if an expression is not foldable the collector writes it to metadata json as an ast for the compiler to resolve phase 2 code generation the collector makes no attempt to understand the metadata that it collects and outputs to metadata json it represents the metadata as best it can and records errors when it detects a metadata syntax violation it s the compiler s job to interpret the metadata json in the code generation phase the compiler understands all syntax forms that the collector supports but it may reject syntactically correct metadata if the semantics violate compiler rules public or protected symbols the compiler can only reference exported symbols decorated component class members must be public or protected you cannot make an input property private data bound properties must also be public or protected supported classes and functions the collector can represent a function call or object creation with new as long as the syntax is valid the compiler however can later refuse to generate a call to a particular function or creation of a particular object the compiler can only create instances of certain classes supports only core decorators and only supports calls to macros functions or static methods that return expressions compiler action details new instances the compiler only allows metadata that create instances of the class injectiontoken from angular core supported decorators the compiler only supports metadata for the angular decorators in the angular core module functions and static method calls the collector accepts any function or static method that contains a single return statement the compiler however only supports macros in the form of functions or static methods that return an expression for example consider the following function export function wrapinarray t value t t return value you can call the wrapinarray in a metadata definition because it returns the value of an expression that conforms to the compiler s restrictive javascript subset you might use wrapinarray like this ngmodule declarations wrapinarray typical export class typicalmodule the compiler treats this usage as if you had written ngmodule declarations typical export class typicalmodule the angular routermodule exports two macro static methods forroot and forchild to help declare root and child routes review the source code for these methods to see how macros can simplify configuration of complex ngmodules phase 3 template type checking one of the angular compiler s most helpful features is the ability to type check expressions within templates and catch any errors before they cause crashes at runtime in the template type checking phase the angular template compiler uses the typescript compiler to validate the binding expressions in templates strict checking in this phase is enabled by default and controlled by the compiler option stricttemplates in the angularcompileroptions of the project s typescript configuration file see angular compiler options template validation produces error messages when a type error is detected in a template binding expression similar to how type errors are reported by the typescript compiler against code in a ts file for example consider the following component component selector my component template person addresss street class mycomponent person person this produces the following error my component ts mycomponent html 1 1 property addresss does not exist on type person did you mean address the file name reported in the error message my component ts mycomponent html is a synthetic file generated by the template compiler that holds contents of the mycomponent class template the compiler never writes this file to disk the line and column numbers are relative to the template string in the component annotation of the class mycomponent in this case if a component uses templateurl instead of template the errors are reported in the html file referenced by the templateurl instead of a synthetic file the error location is the beginning of the text node that contains the interpolation expression with the error if the error is in an attribute binding such as value person address street the error location is the location of the attribute that contains the error the validation uses the typescript type checker and the options supplied to the typescript compiler to control how detailed the type validation is for example if the strictnullchecks typescript option is enabled the error my component ts mycomponent html 1 1 object is possibly undefined is reported as well as the above error message type narrowing the expression used in an ngif directive is used to narrow type unions in the angular template compiler the same way the if expression does in typescript for example to avoid object is possibly undefined error in the template above modify it to only emit the interpolation if the value of person is initialized as shown below component selector my component template span ngif person person address street span class mycomponent person person using ngif allows the typescript compiler to infer that the person used in the binding expression will never be undefined for more information about input type narrowing see improving template type checking for custom directives non null type assertion operator use the non null type assertion operator to suppress the object is possibly undefined error when it is inconvenient to use ngif or when some constraint in the component ensures that the expression is always non null when the binding expression is interpolated in the following example the person and address properties are always set together implying that address is always non null if person is...
|