ng generate interface command in Angular CLI

ng generate interface command is used to create interfaces in Angular applications

ng generate interface syntax

ng generate interface command takes two parameters name and type

Additionally we can pass different options as well.

ng generate interface [name] [type] [options]

or you can use shorthand syntax

ng generate i [name] [type] [options]

ng generate interface arguments

ng generate interface command takes two argument i.e, name and type.

  1. name : name of the interface.
  2. type : Adds a developer-defined type to the filename, in the format “name.type.ts”.

The name and type both are strings.

ng generate interface options

ng generate interface accepts 2 different types of options.

  1. prefix
  2. project
OptionDescriptionTypeDefault Value
prefixA prefix to apply to generated selectors.string
projectThe name of the project.string

ng generate interface example

For example if you want to create a interface named product, use ng generate i product interface command.

CREATE src/app/product.interface.ts (29 bytes)

The type is optional parameter.

> ng generate i user
CREATE src/app/user.ts (26 bytes)
Avatar

Arunkumar Gudelli

Liked this post? Subscribe