# @codehint-ng/html-compiler

> A simple component to display dynamic Angular components.

Latest version **1.0.8** (published 2020-04-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @codehint-ng/html-compiler
pnpm add @codehint-ng/html-compiler
yarn add @codehint-ng/html-compiler
bun add @codehint-ng/html-compiler
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2020-04-20 |
| First published | 2020-03-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 150.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | mazhekin |
| Keywords | Angular |

## Links

- npm: https://www.npmjs.com/package/@codehint-ng/html-compiler
- Repository: https://github.com/codehint-ng/ng-controls
- Homepage: https://github.com/codehint-ng/ng-controls#readme
- Issues: https://github.com/codehint-ng/ng-controls/issues
- npm.io page: https://npm.io/package/@codehint-ng/html-compiler

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^1.9.0

## Recent versions

- 1.0.8 (latest) — 2020-04-20
- 1.0.7 — 2020-04-09
- 0.9.0 — 2020-04-09
- 1.0.6 — 2020-03-31
- 1.0.5 — 2020-03-30
- 1.0.4 — 2020-03-30
- 1.0.3 — 2020-03-30
- 1.0.2 — 2020-03-28
- 1.0.1 — 2020-03-28
- 1.0.0 — 2020-03-28

## README

# @codehint-ng/html-compiler

A simple component to display dynamic Angular components.

## Usage

**!!!NOTE** For production version see note below.

1) Register the @codehint-ng/html-compiler in your module:

        import { CngHtmlCompilerModule } from '@codehint-ng/html-compiler';

        @NgModule({
        imports: [
            CngHtmlCompilerModule
            ...
        ],
        ...

2) Define dynamic component (angular syntax):

       this.template = '<div>hello {{name}}</div> <button (click)="onEvent()">Test Event</button>';
       this.componentClass = {
           name: 'World!',
           onEvent: () => { alert('this is event'); }
        };

3) Use cng-html-compiler to display dynamic component:
           
       <cng-html-compiler [template]="template"
                          [componentClass]="componentClass">
       </cng-html-compiler>
  
**!!!NOTE**
To work correctly application in production, do not forget to register JitCompilerModule in your main app.module.

    import { JitCompilerModule } from '@codehint-ng/html-compiler';
            
     @NgModule({
         imports: [
             // workaround: The issue: Runtime compiler is not loaded.   
             JitCompilerModule // !once only, !in main app.module only
                 ...
          ],
          ...
      })
      export class AppModule { }    

**Addition**
1) If you want to place in template string some Angular component (your own or third party) 
you need to add origin module into property imports component cng-html-compiler 
       
       this.template = '<my-or-third-party-component ...></my-or-third-party-component>';
       this.componentClass = {...};
       this.imports = [MyOrThirtPartyModule];
       ...
       
And pass this parameter into cng-html-compiler:     
              
       <cng-html-compiler [template]="template"
                          [componentClass]="componentClass"
                          [imports]="imports">
       </cng-html-compiler>
       
2) Html Compiler allows to get rendered html also:
        
       @ViewChild(CngHtmlCompilerComponent, {static: true}) htmlCompilerComponent: CngHtmlCompilerComponent;
       
       const sourceHtml = this.htmlCompilerComponent.getSourceHtml();

---
_Source: https://npm.io/package/@codehint-ng/html-compiler · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
