Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
@ngxd/core
Advanced tools
🥳 Best way to quickly use Dynamic Components with Angular
Use like NgComponentOutlet
but with @Input/@Output
auto bindings:
<ng-container *ngxComponentOutlet="component"></ng-container>
Here is a demo example showing NGX Dynamic and Angular in action.
There are several modes of operation of the directive.
A simple variant of binding through the parent component.
@Component({
template: `
<ng-container
*ngxComponentOutlet="component"></ng-container>`
// using @ngxd/core 👆
})
class MyComponent {
// 🥳 inputs and outputs will binding automatically
@Input() entity;
@Output() action;
// your dynamic component 👇
component = DynamicComponent;
}
Additionally there is autobinding through the context. This is useful when you need to display something through *ngFor. Context has a higher priority than the inputs in the component.
<ng-container *ngFor=“let color of colors”
<ng-container
*ngxComponentOutlet="
component;
context: { color: color }"></ng-container>
</ng-container>
For ease of selecting the required component, there is ResolvePipe, which expects NgxdResolver to enter, and returns the required component.
<ng-container
*ngxComponentOutlet="
resolver | resolve: entity"></ng-container>
Through the host component, when the inputs and outputs are initialized explicitly. This option is difficult to use and deprecated.
<!-- host component -->
<app-dynamic
<!-- dynamic component -->
[ngxComponentOutlet]="component"
<!-- regular input -->
[entity]="entity"
<!-- regular output -->
(action)="onAction($event)">
</app-dynamic>
Feature | NgxComponentOutlet | ComponentFactoryResolver | NgComponentOutlet |
---|---|---|---|
Friendliness | ⭐⭐⭐ | ⭐ | ⭐⭐ |
Dynamic Components | ✅ | ✅ | ✅ |
AOT support | ✅ | ✅ | ✅ |
Reactivity | ✅ | ✅ | ✅ |
Injector | ✅ | ✅ | ✅ |
NgModule | ✅ | ✅ | ✅ |
projectionNodes | ✅ | ✅ | ✅ |
Component Access | ✅ | ✅ | ❌ |
Lifecycle OnChanges | ✅ | ⭕️ manually | ❌ |
Binding @Input() | ✅ | ⭕️ manually | ❌ |
Binding @Output() | ✅ | ⭕️ manually | ❌ |
Activate Event | ✅ | ⭕️ manually | ❌ |
Deactivate Event | ✅ | ⭕️ manually | ❌ |
@ngxd/core
:npm install --save @ngxd/core
# or
yarn add @ngxd/core
import { NgxdModule } from '@ngxd/core';
@NgModule({
declarations: [ AppComponent ],
// have import NgxdModule here 👇
imports: [ BrowserModule, NgxdModule ],
bootstrap: [ AppComponent ]
})
export class AppModule {}
@Component({
template: `
<ng-container
*ngxComponentOutlet="component"></ng-container>`
// using @ngxd/core 👆
})
class MyComponent {
// 🥳 inputs and outputs will binding automatically
@Input() entity;
@Output() action;
// your dynamic component 👇
component = DynamicComponent;
}
Input | Type | Default | Required | Description |
---|---|---|---|---|
[ngxComponentOutlet] | Type<any> | n/a | yes | |
[ngxComponentOutletContext] | any | n/a | no | |
[ngxComponentOutletInjector] | Injector | n/a | no | |
[ngxComponentOutletContent] | any[][] | n/a | no | |
[ngxComponentOutletNgModuleFactory] | NgModuleFactory<any> | n/a | no |
Output | Type | Description |
---|---|---|
(ngxComponentOutletActivate) | any | |
(ngxComponentOutletDeactivate) | any |
FAQs
NGXD is a dynamic pattern + library for Angular
The npm package @ngxd/core receives a total of 4,075 weekly downloads. As such, @ngxd/core popularity was classified as popular.
We found that @ngxd/core demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.