1

I would like to be able to create developer purpose components that would provide some usefull debugging information (for example eg internal state of the component) which could be included into the application views just like any other component but only if this is not a production environment. It would be something like

<my-component #subject></my-component>

<ng-container *ngIf='!isProduction'>
    <dev-debug-inspector [subject]="subject"></dev-debug-inspector>
</ng-container> 
  1. I would like to be able to include such components into view just like any other components
  2. It MUST be a lazy load compoent as I dont want those to bundled into feature modules - so production would stay clean (having not loaded modules in the production files would be fine I guess)

Is it possible ?

1 Answer 1

2

It's definitely possible to lazy load a component based on some conditions without using the router.

Example:

public lazyDevComponent = null;

constructor() {
  if (!isProduction) {
    this.lazyDevComponent = import(`../routing-step-details-per-types/types/cam/cam.component`).then(
      ({ CamComponent }) => CamComponent,
    );
  }
}

and on TS side:

<ng-template
  *ngIf="lazyDevComponent"
  [ngComponentOutlet]="lazyDevComponent"
></ng-template> 
Sign up to request clarification or add additional context in comments.

2 Comments

I didn't expect it to be that easy. What about data binding to CamComponent?
can't but you can use a service from that component to get whatever you need

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.