{ "id": "guide/language-service", "title": "Angular Language Service", "contents": "\n\n\n
The Angular Language Service provides code editors with a way to get completions, errors,\nhints, and navigation inside Angular templates.\nIt works with external templates in separate HTML files, and also with in-line templates.
\nYour editor autodetects that you are opening an Angular file.\nIt then uses the Angular Language Service to read your tsconfig.json
file, find all the\ntemplates you have in your application, and then provide language services for any templates that you open.
Language services include:
\nAutocompletion can speed up your development time by providing you with\ncontextual possibilities and hints as you type.\nThis example shows autocomplete in an interpolation. As you type it out,\nyou can hit tab to complete.
\nThere are also completions within elements. Any elements you have as a component selector will\nshow up in the completion list.
\nThe Angular Language Service can forewarn you of mistakes in your code.\nIn this example, Angular doesn't know what orders
is or where it comes from.
The quick-info feature allows you to hover to see where components, directives, modules, and so on come from.\nYou can then click \"Go to definition\" or press F12 to go directly to the definition.
\nAngular Language Service is currently available as an extension for Visual Studio Code,\nWebStorm, Sublime Text and Eclipse IDE.
\nIn Visual Studio Code, install the extension from the Extensions: Marketplace. You can open the marketplace from the editor using the Extensions icon on the left menu pane, or use VS Quick Open (⌘+P on Mac, CTRL+P on Windows) and type \"? ext\". In the marketplace, search for Angular Language Service extension, and click the Install button.
\nThe Visual Studio Code integration with the Angular language service is maintained and distributed by the Angular team.
\nIn Visual Studio, install the extension from the Extensions: Marketplace. You can open the marketplace from the editor selecting Extensions on the top menu pane, and then selecting Manage Extensions. In the marketplace, search for Angular Language Service extension, and click the Install button.
\nThe Visual Studio integration with the Angular language service is maintained and distributed by Microsoft with help from the Angular team. Check out the project here
\nIn WebStorm, enable the plugin Angular and AngularJS.
\nSince WebStorm 2019.1, the @angular/language-service
is not required anymore and should be removed from your package.json
.
In Sublime Text, the Language Service supports only in-line templates when installed as a plug-in.\nYou need a custom Sublime plug-in (or modifications to the current plug-in) for completions in HTML files.
\nTo use the Language Service for in-line templates, you must first add an extension to allow TypeScript, then install the Angular Language Service plug-in. Starting with TypeScript 2.3, TypeScript has a plug-in model that the language service can use.
\nnode_modules
directory:\"compilerOptions\"
section of your project's tsconfig.json
.Cmd+,
or Ctrl+,
), add the following:This allows the Angular Language Service to provide diagnostics and completions in .ts
files.
Either directly install the \"Eclipse IDE for Web and JavaScript developers\" package which comes with the Angular Language Server included, or from other Eclipse IDE packages, use Help > Eclipse Marketplace to find and install Eclipse Wild Web Developer.
\nWhen you use an editor with a language service, the editor starts a separate language-service process\nand communicates with it through an RPC, using the Language Server Protocol.\nWhen you type into the editor, the editor sends information to the language-service process to\ntrack the state of your project.
\nWhen you trigger a completion list within a template, the editor first parses the template into an\nHTML abstract syntax tree (AST).\nThe Angular compiler interprets that tree to determine the context: which module the template is part of, the current scope, the component selector, and where your cursor is in the template AST. It can then determine the symbols that could potentially be at that position..
\nIt's a little more involved if you are in an interpolation.\nIf you have an interpolation of {{data.---}}
inside a div
and need the completion list after data.---
, the compiler can't use the HTML AST to find the answer.\nThe HTML AST can only tell the compiler that there is some text with the characters \"{{data.---}}
\".\nThat's when the template parser produces an expression AST, which resides within the template AST.\nThe Angular Language Services then looks at data.---
within its context, asks the TypeScript Language Service what the members of data
are, and returns the list of possibilities.
For more in-depth information on the implementation, see the\nAngular Language Service API.
\nFor more on the design considerations and intentions, see design documentation here.
\nSee also Chuck Jazdzewski's presentation on the Angular Language Service from ng-conf 2017.
\n