From the course: Learning the Angular CLI

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Generating directives

Generating directives - Angular Tutorial

From the course: Learning the Angular CLI

Start my 1-month free trial

Generating directives

- Generating directives can also be achieved using simple commands. Let's suppose we need to generate a directive to modify input elements to only accept text input and name this directive, non-numeric. At the terminal, we can simply type in ng generate directive and we will be placing this in the shared module as well, inside a directives folder. In this case, let's explicitly tell the CLI the declaring model. And we can do that by specifying the --module=shared. A directive file was generated along with a spec file. Note also that the app prefix is added to the directive selector and it's also automatically imported to the shared module.

Contents