@nx/angular:directive

Creates a new Angular directive.

Usage

1nx generate directive ... 2
1nx g d ... #same 2

By default, Nx will search for directive in the default collection provisioned in workspace.json.

You can specify the collection explicitly as follows:

1nx g @nx/angular:directive ... 2

Show what will be generated without writing to disk:

1nx g directive ... --dry-run 2

Examples

Generate a directive with the exported symbol matching the file name. It results in the directive FooDirective at mylib/src/lib/foo.directive.ts:

1nx g @nx/angular:directive mylib/src/lib/foo.directive.ts 2

Generate a directive without providing the file extension. It results in the directive FooDirective at mylib/src/lib/foo.directive.ts:

1nx g @nx/angular:directive mylib/src/lib/foo 2

Generate a directive with the exported symbol different from the file name. It results in the directive CustomDirective at mylib/src/lib/foo.directive.ts:

1nx g @nx/angular:directive mylib/src/lib/foo --name=custom 2

Options

path

Required
string

The file path to the directive. Relative to the current working directory.

export

boolean
Default: false

The declaring NgModule exports this directive.

module

m
string

The filename of the declaring NgModule.

name

string

The directive symbol name. Defaults to the last segment of the file path.

prefix

p
oneOf [string, string]

A prefix to apply to generated selectors.

skipTests

boolean
Default: false

Do not create "spec.ts" test files for the new class.

skipImport

boolean
Default: false

Do not import this directive into the owning NgModule.

selector

string
Format: html-selector

The HTML selector to use for this directive.

standalone

boolean
Default: true

Whether the generated directive is standalone.

skipFormat

boolean
Default: false

Skip formatting of files.