Page Contents

Home > @loopback/core > Application > component

Application.component() method

Add a component to this application and register extensions such as controllers, providers, and servers from the component.

Signature:

component<T extends Component = Component>(componentCtor: Constructor<T>, nameOrOptions?: string | BindingFromClassOptions): Binding<T>;

Parameters

Parameter Type Description
componentCtor Constructor<T> The component class to add.
nameOrOptions string | BindingFromClassOptions (Optional) Optional component name or options, default to the class name

Returns:

Binding<T>

Example


export class ProductComponent {
  controllers = [ProductController];
  repositories = [ProductRepo, UserRepo];
  providers = {
    [AUTHENTICATION_STRATEGY]: AuthStrategy,
    [AUTHORIZATION_ROLE]: Role,
  };
};

app.component(ProductComponent);