1

I'm using an internal library that provides a generic solution for authentication, including a login page with a login form. For a specific application, I need to customize the login form by adding additional functionality and changing the layout (HTML).

Is it possible to override the login form component provided by the library without creating a completely new custom login page?

Here is what I have tried so far:

@Component({
  //same selector
  selector: 'login-form',
  templateUrl: './custom-login.component.html',
  styleUrls: ['./custom-login.component.scss'],
  providers: [
    {
      provide: LoginComponent,
      useExisting: CustomLoginComponent,
    },
  ],
})
export class CustomLoginComponent extends LoginComponent {}

However, this approach doesn't seem to work as expected. The original login form from the library is still being displayed instead of my custom form.

Questions:

Is it possible to override a component from a 3rd party library in Angular by extending it and using the same selector? If so, what is the correct way to achieve this? Are there any alternative methods to customize a component from a 3rd party library without creating a completely new component?

2
  • 1
    is the login-form selector used in your application, or inside the 3rd party library. Commented Jul 22, 2024 at 12:30
  • The login-form is used inside the 3d party library Commented Jul 23, 2024 at 8:04

1 Answer 1

1

No you can't replace a component provided and used inside the library in a runtime app.

This is only possible in testing scenarios to enable stub components.

Sign up to request clarification or add additional context in comments.

2 Comments

This means that the third party should provide a solution for this, right? The only think which comes into my mind is using a template which you can register using forRoot but this doesn'T allow adding new functionalities to an existing component.
Yes, most likely via TemplateOutlet or a ComponentOutlet

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.