skip to content

What does the Angular Language Service add to a code editor, and why does it work best with strictTemplates enabled?

level: juniorimportance: nice to knowfreq 22%

answer

  1. editors understand templates too
  2. reads the project's tsconfig
  3. completions, errors, hover, navigation
  4. strict types give precise answers

basics

~20 s

The Angular Language Service gives editors template intelligence: completions, the compiler's own diagnostics, quick info on hover and go-to-definition, for inline and external templates. It reads tsconfig, so with strictTemplates it sees precise template types and gives the most accurate results.

solid answer

~50 s

TypeScript tooling alone treats an Angular template as a string or plain HTML. The **Angular Language Service** runs the Angular compiler's analysis inside the editor. It reads the project's `tsconfig.json`, finds every component's template - inline or in a `templateUrl` file - and offers **completions** (component selectors, inputs, properties of the component in interpolations), **diagnostics** (the same template errors `ng build` would report), **quick info** on hover showing where a component or directive comes from, and **go to definition** from a template tag or binding to its TypeScript source. The docs recommend `strictTemplates: true` to enable the latest features, because strict mode gives the compiler exact types for bindings, `$event` and local references; with looser checking, many expressions are `any` and completions and errors become vaguer. Since Angular 22 strict mode is the default unless a tsconfig sets it to false. It ships as an extension for common editors.

go deeper

for a junior

Know that installing the Angular Language Service gives completions, errors and go-to-definition inside templates, both inline and in HTML files.

for a middle

Explain that it reads tsconfig and runs the compiler's analysis, and why strictTemplates makes its completions and diagnostics precise.

for a senior

Diagnose editor-versus-build disagreements, such as a wrong tsconfig or stale extension, and use it to keep template errors from ever reaching CI.

for a principal

Standardise editor tooling and compiler options across teams so that the editor, CI and production builds all enforce the same template rules.

## The gap it fills A TypeScript-aware editor understands `.ts` files, but an Angular template is a string inside a decorator or a separate `.html` file. Without help the editor cannot tell that `<app-cart>` is a component, that `[items]` is one of its inputs, or that `{{ totl }}` is a typo for `total`. The **Angular Language Service** closes that gap by running the Angular compiler's template analysis inside the editor. ## What it provides | Feature | Example | | :-- | :-- | | **Completions** | Typing `<app-` lists component selectors; inside `{{ }}` it lists the component's properties | | **Diagnostics** | Red underlines for unknown elements, missing properties or type mismatches, the same errors the build reports | | **Quick info** | Hovering a tag or binding shows which component, directive or pipe it resolves to and where it comes from | | **Go to definition** | Jumps from a template tag or binding to the TypeScript source | It works for **inline** templates and for **external** templates in `templateUrl` files. ## How it finds your templates 1. The editor detects an Angular project and starts the Language Service. 2. The service reads the project's `tsconfig.json`, including `angularCompilerOptions`. 3. It analyses the program the way the compiler would, locating every component and its template. 4. When you open a template, it answers editor requests from that analysis. Because it uses the project's real compiler configuration, the editor and `ng build` agree about which templates are errors. ## Why `strictTemplates` matters The official setup guidance is to set `strictTemplates: true` to enable the latest Language Service features. The reason is type precision: - In strict mode the compiler knows the exact type of each input binding, of `$event` for outputs and DOM events, and of `#ref` local references. - In basic mode many of those are `any`, so completions after `$event.` or `ref.` have nothing to list, and type errors inside embedded views go unreported. - Extended diagnostics, such as a warning for a signal interpolated without `()`, only emit in strict mode, so the editor shows them only then. Since Angular 22, `strictTemplates` defaults to `true`; an upgraded project may still carry an explicit `false` written by the upgrade migration, which quietly weakens the editor experience. ## Getting it - Most editors get it as an **extension or plugin**; the Visual Studio Code extension is maintained by the Angular team. - After changing `angularCompilerOptions`, restart the language server so it re-reads the configuration. ## Troubleshooting checklist - **No template features at all**: check that the extension is installed and that the editor opened the workspace folder containing `tsconfig.json`. - **Errors in the editor but not in the build (or the reverse)**: the editor may be using a different tsconfig, or an outdated extension; restart the language server after changing `angularCompilerOptions`. - **Everything is `any`**: `strictTemplates` is probably `false`. ## What it does not do - It does not run or inspect the live application; that is the job of Angular DevTools and the `ng` console global. - It does not format templates; formatting belongs to a formatter. - It cannot be more precise than the project's types: a library whose typings are loose yields loose completions. ## Where it sits among debugging tools - The **Language Service** catches template mistakes as you type, before anything runs. - **`ng build`** reports the same diagnostics in CI. - **Angular DevTools** and the `ng` console global inspect the running application. Together they cover the path from writing a template to inspecting it live.

  • Why can the Angular Language Service show the same template errors as ng build?
    It reads the same `tsconfig.json` and `angularCompilerOptions` and runs the Angular compiler's template analysis on the same program, so both see identical types and flags. When they disagree, the usual cause is the editor using a different tsconfig or an outdated extension, fixed by pointing it at the right workspace and restarting the language server.
  • What does an Angular developer lose in the editor when strictTemplates is set to false?
    Template expressions lose precise types: `$event`, local references and many bindings become `any`. Completions after those expressions become empty or generic, type errors inside embedded views are not reported, and extended diagnostics disappear entirely, because they only run in strict mode.

  • The Language Service only works with external .html templates, not inline ones.
  • It uses its own rules, so editor errors often disagree with ng build.
  • It is a code formatter for Angular templates.
  • strictTemplates has no effect on what the editor can show.
  • The Language Service inspects the running app like DevTools does.