Visual Studio Code extension allowing you to generate Angular schematics with a Graphical User Interface.
Works with Ionic Angular projects too!
This extension will save you time:
- Simple interface for Angular CLI: no command line required
- Many options are pre-filled
- The generated file will auto open
- No more typo errors
- No more search in documentation: all options available are described
This extension promote Angular good practices, by improving component generation with the suggestion of different component types (explained below). To separate component types is good for:
- the architecture of your project, ie. maintainability and scalability,
- performances: pure components are optimized.
I started this project to help my students learning Angular. Now, according to Visual Studio Code Marketplace, this extension helps more than 270 000 developers like you to be more productive.
It's a lot of free work. So if your company earns money with projects using this extension, consider becoming a sponsor.
- @ngx-pwa/local-storage: Angular library for local storage
- typescript-strictly-typed: strict config for TypeScript, ESLint/TSLint and Angular
- Popular Angular posts on Medium
- Follow updates of this lib on Twitter
- Angular onsite trainings (based in Paris, so the website is in French, but my English bio is here and I'm open to travel)
Follow instructions on Visual Studio Code marketplace, or just search for "Angular schematics" by "Cyrille Tuzi" directly inside VS Code Extensions view.
Then, you can launch Angular CLI commands from 4 places:
- the Explorer: right-click on a directory, then choose "Angular: Generate..."
- the dedicated Angular Schematics view (icon in the Activity bar on the left)
- the Command Palette
- with a keyboard shortcut
The quickest way to launch a generation is the first: a right-click on a directory in the Explorer. Why? Because in this scenario, the extension will automatically infer the path where you want to generate the schematic.
This extension requires Visual Studio Code version >= 1.41.
Basically, in your project, if ng g component hello
works
in the VS Code Terminal, the extension should work.
If the Angular CLI is not working in the VS Code Terminal, please correct that first before opening a GitHub issue. See the troubleshooting guide for help.
Since VS Code 1.41, a new default behavior combines single folders together.
While it might be a good idea in general, it is annoying with this extension, as clicking on the right directory where you want to generate something becomes more confusing.
So you should consider disabling this setting in your VS Code workspace preferences:
"explorer.compactFolders": false
The extension supports Ionic projects too, but it is recommended to adjust some Ionic settings.
This extension helps you to follow good practices, by suggesting different component types.
Learn more about Angular components types.
Option pre-filled: --skip-selector
A component associated to a route relies on specific features
(like the ActivatedRoute
service to get URL params).
Thus, it should not be called via a HTML tag and so should not have a selector.
Option pre-filled: --change-detection OnPush
A pure component, also known as a presentation component,
is a component which relies only on its @Input
s for data, ie. its role is only presentation / UI (~ view),
as opposed to an impure component, which relies on external asynchronous operations (like a HTTP request via a service) for data, ie. a page (~ controller).
Learn more about architecture in Angular projects.
Options pre-filled: --export --change-detection OnPush
Components have a local scope by default, meaning they are only usable inside the module where they are declared. So if you want to use a component in another module (for example if you are doing a reusable UI component), you have to export it.
Learn more about Angular modules and their scopes.
Angular CLI >= 9 introduces a new --type
option for component generation, to change the component's suffix.
For example, ng g hello --type page
will generate the hello.page.ts
file with a HelloPage
class
(instead of the hello.component.ts
file with a HelloComponent
class).
The extension will add --type page
automatically for Pages if
you change the authorized suffixes in your tslint.json:
{
"rules": {
"component-class-suffix": [true, "Component", "Page"]
}
}
The extension suggests these additional component types if the related libraries are installed:
- Angular Material dialog
- Angular Material snackbar
- Angular Material bottomsheet
- Ionic modal
- Ionic popover
- PrimeNG dynamic dialog
As for Pages, a custom --type
/suffix will be automatically added
if your tslint.json
is configured accordingly.
Library authors are encouraged to create a Pull Request to
easily add defaults components types in
src/defaults.ts
.
You can add custom component types in your VS Code preferences (preferably your workspace preferences, so all your team can benefit).
For example, non-Ivy projects (ie. Angular <= 8 or Angular >= 9 with Ivy manually disabled) can add this deprecated component type for modals/dialogs:
{
"ngschematics.componentTypes": [{
"label": "Entry component",
"options": [["entryComponent", "true"], ["skipSelector", "true"]],
"detail": "Component instanciated at runtime, like a dialog or modal",
}]
}
schematics
option of angular.json
allows to save default options for schematics commands.
For example, if you want all your generated components templates to be inline, in all your projects,
just add in angular.json
:
{
"schematics": {
"@schematics/angular:component": {
"inlineTemplate": true
} } }
Or only in a specific project:
{
"projects": {
"yourprojectname": {
"schematics": {
"@schematics/angular:component": {
"inlineTemplate": true
} } } } }
It can be interesting for the following options:
@schematics/angular:component
inlineTemplate
inlineStyle
style
prefix
changeDetection
viewEncapsulation
displayBlock
(Angular CLI >= 9.1)
- all schematics
flat
skipTests
By default, this extension detects the following schematics:
@schematics/angular
(official Angular CLI commands)@angular/material
@ionic/angular-toolkit
@ngrx/schematics
@ngxs/schematics
@nativescript/schematics
@ngx-formly/schematics
primeng-schematics
@ngx-kit/collection
ngx-spec
./schematics/collection.json
Scanning all packages to find all potential schematics would be too slow.
If you are a library author, you can open a Pull Request to easily add your schematics package in the
src/defaults.ts
.
If you created your own Angular schematics,
this extension can load them too. By default, the extension will look into ./schematics/collection.json
.
If your schematics collection path is different, you can add:
- a relative path in VS Code preferences:
"ngschematics.schematics": ["./path/to/collection.json"]
- if it's a package in
node_modules
:"ngschematics.schematics": ["my-private-lib"]
If you work with multiple projects at the same time, the extension supports:
- VS Code workspace folders
- Angular CLI monorepo (several
ng g application
s and/orng g library
s in the same project) - Hoisted
node_modules
(eg. Yarn workspaces)
Using a right-click on a directory in the Explorer to launch a schematic generation is essential in both these cases, as the Code workspace folder and/or the Angular project will be automatically inferred by the extension. Otherwise you will have to choose them manually.
MIT