Giter Club home page Giter Club logo

ng-dynamic-component's Introduction

ng-dynamic-component

Dynamic components with full life-cycle support for inputs and outputs

Release Workflow Test Workflow Appveyor Coverage Maintainability Npm Npm Downloads Licence semantic-release

Hey! There is a proposal for new API!

So if you are using this library please give your vote/feedback.

Compatibility with Angular
Angular ng-dynamic-component NPM package
>=14.1.3 10.3.1 ng-dynamic-component@^10.3.1
>=14.x.x 10.2.x ng-dynamic-component@^10.2.0
13.x.x 10.1.x ng-dynamic-component@~10.1.0
12.x.x 9.x.x ng-dynamic-component@^9.0.0
11.x.x 8.x.x ng-dynamic-component@^8.0.0
10.x.x 7.x.x ng-dynamic-component@^7.0.0
9.x.x 6.x.x ng-dynamic-component@^6.0.0
8.x.x 5.x.x ng-dynamic-component@^5.0.0
7.x.x 4.x.x ng-dynamic-component@^4.0.0
6.x.x 3.x.x ng-dynamic-component@^3.0.0
5.x.x 2.x.x ng-dynamic-component@^2.0.0
4.x.x 1.x.x ng-dynamic-component@^1.0.0
2.x.x 0.x.x ng-dynamic-component@^0.0.0

Installation

$ npm install ng-dynamic-component --save

Usage

DynamicComponent

Import DynamicModule where you need to render dynamic components:

import { DynamicModule } from 'ng-dynamic-component';

@NgModule({
  imports: [DynamicModule],
})
export class MyModule {}

Then in your component's template include <ndc-dynamic> where you want to render component and bind from your component class type of component to render:

@Component({
  selector: 'my-component',
  template: ` <ndc-dynamic [ndcDynamicComponent]="component"></ndc-dynamic> `,
})
class MyComponent {
  component = Math.random() > 0.5 ? MyDynamicComponent1 : MyDynamicComponent2;
}

Standalone API

Since v10.7.0

You may use <ndc-dynamic> as a standalone component:

import { DynamicComponent } from 'ng-dynamic-component';

@Component({
  selector: 'my-component',
  template: ` <ndc-dynamic [ndcDynamicComponent]="component"></ndc-dynamic> `,
  imports: [DynamicComponent],
  standalone: true,
})
class MyComponent {
  component = Math.random() > 0.5 ? MyDynamicComponent1 : MyDynamicComponent2;
}

NOTE: Hovewer you should be aware that this will only import <ndc-dynamic> into your component and nothing else so things like dynamic inputs/outputs will not work and you will have to import them separately (see their respective sections).

If you still need to use both <ndc-dynamic> and dynamic inputs/outputs it is recommended to keep using DynamicModule API.

NgComponentOutlet

You can also use NgComponentOutlet directive from @angular/common instead of <ndc-dynamic>.

Import DynamicIoModule where you need to render dynamic inputs:

import { DynamicIoModule } from 'ng-dynamic-component';

@NgModule({
  imports: [DynamicIoModule],
})
export class MyModule {}

Now apply ndcDynamicInputs and ndcDynamicOutputs to ngComponentOutlet:

@Component({
  selector: 'my-component',
  template: `<ng-template [ngComponentOutlet]="component"
                           [ndcDynamicInputs]="inputs"
                           [ndcDynamicOutputs]="outputs"
                           ></ng-template>`
})
class MyComponent {
  component = MyDynamicComponent1;
  inputs = {...};
  outputs = {...};
}

Also you can use ngComponentOutlet with * syntax:

@Component({
  selector: 'my-component',
  template: `<ng-container *ngComponentOutlet="component;
                            ndcDynamicInputs: inputs;
                            ndcDynamicOutputs: outputs"
                            ></ng-container>`
})
class MyComponent {
  component = MyDynamicComponent1;
  inputs = {...};
  outputs = {...};
}

Standalone API

Since v10.7.0

You may use dynamic inputs/outputs with *ngComponentOutlet as a standalone API:

import { ComponentOutletInjectorModule } from 'ng-dynamic-component';

@Component({
  selector: 'my-component',
  template: `<ng-container *ngComponentOutlet="component;
                            ndcDynamicInputs: inputs;
                            ndcDynamicOutputs: outputs"
                            ></ng-container>`
  imports: [ComponentOutletInjectorModule],
  standalone: true,
})
class MyComponent {
  component = MyDynamicComponent1;
  inputs = {...};
  outputs = {...};
}

If you want to use standard dynamic inputs/outputs with ngComponentOutlet as a standalone API you need to add the DynamicIoDirective to your imports:

import { DynamicIoDirective, ComponentOutletInjectorModule } from 'ng-dynamic-component';

@Component({
  selector: 'my-component',
  template: `<ng-container *ngComponentOutlet="component;
                            ndcDynamicInputs: inputs;
                            ndcDynamicOutputs: outputs"
                            ></ng-container>`
  imports: [DynamicIoDirective, ComponentOutletInjectorModule],
  standalone: true,
})
class MyComponent {
  component = MyDynamicComponent1;
  inputs = {...};
  outputs = {...};
}

Inputs and Outputs

You can pass inputs and outputs to your dynamic components:

Import module DynamicIoModule and then in template:

@Component({
  selector: 'my-component',
  template: `
    <ndc-dynamic
      [ndcDynamicComponent]="component"
      [ndcDynamicInputs]="inputs"
      [ndcDynamicOutputs]="outputs"
    ></ndc-dynamic>
  `,
})
class MyComponent {
  component = MyDynamicComponent1;
  inputs = {
    hello: 'world',
    something: () => 'can be really complex',
  };
  outputs = {
    onSomething: (type) => alert(type),
  };
}

@Component({
  selector: 'my-dynamic-component1',
  template: 'Dynamic Component 1',
})
class MyDynamicComponent1 {
  @Input()
  hello: string;
  @Input()
  something: Function;
  @Output()
  onSomething = new EventEmitter<string>();
}

Here you can update your inputs (ex. inputs.hello = 'WORLD') and they will trigger standard Angular's life-cycle hooks (of course you should consider which change detection strategy you are using).

Standalone API

Since v10.7.0

You can use standalone API to pass dynamic inputs/outputs using DynamicIoDirective with DynamicComponent or ngComponentOutlet:

import { DynamicIoDirective, DynamicComponent } from 'ng-dynamic-component';

@Component({
  selector: 'my-component',
  template: `
    <ndc-dynamic
      [ndcDynamicComponent]="component"
      [ndcDynamicInputs]="inputs"
      [ndcDynamicOutputs]="outputs"
    ></ndc-dynamic>
  `,
  imports: [DynamicIoDirective, DynamicComponent]
})
class MyComponent {
  component = MyDynamicComponent1;
  inputs = {...};
  outputs = {...};
}

Output template variables

Since v6.1.0

When you want to provide some values to your output handlers from template - you can do so by supplying a special object to your output that has shape {handler: fn, args: []}:

@Component({
  selector: 'my-component',
  template: `
    <ndc-dynamic
      [ndcDynamicComponent]="component"
      [ndcDynamicOutputs]="{
        onSomething: { handler: doSomething, args: ['$event', tplVar] }
      }"
    ></ndc-dynamic>
  `,
})
class MyComponent {
  component = MyDynamicComponent1;
  tplVar = 'some value';
  doSomething(event, tplValue) {}
}

Here you can specify at which argument event value should arrive via '$event' literal.

HINT: You can override event literal by providing IoEventArgumentToken in DI.

Output Handler Context

Since v10.4.0

You can specify the context (this) that will be used when calling the output handlers by providing either:

  • IoEventContextToken - which will be; injected and used directly as a context value
  • IoEventContextProviderToken - which will be provided and instantiated within the IoService and used as a context value.
    This useful if you have some generic way of retrieving a context for every dynamic component so you may encapsulate it in an Angular DI provider that will be instantiated within every component's injector;

Example using your component as an output context:

import { IoEventContextToken } from 'ng-dynamic-component';

@Component({
  selector: 'my-component',
  template: `
    <ndc-dynamic
      [ndcDynamicComponent]="component"
      [ndcDynamicOutputs]="{
        onSomething: doSomething
      }"
    ></ndc-dynamic>
  `,
  providers: [
    {
      provide: IoEventContextToken,
      useExisting: MyComponent,
    },
  ],
})
class MyComponent {
  component = MyDynamicComponent1;
  doSomething(event) {
    // Here `this` will be an instance of `MyComponent`
  }
}

Component Creation Events

You can subscribe to component creation events, being passed a reference to the ComponentRef:

@Component({
  selector: 'my-component',
  template: `
    <ndc-dynamic
      [ndcDynamicComponent]="component"
      (ndcDynamicCreated)="componentCreated($event)"
    ></ndc-dynamic>
  `,
})
class MyComponent {
  component = MyDynamicComponent1;
  componentCreated(compRef: ComponentRef<any>) {
    // utilize compRef in some way ...
  }
}

Attributes

Since v2.2.0 you can now declaratively set attributes, as you would inputs, via ndcDynamicAttributes.

Import module DynamicAttributesModule and then in template:

import { AttributesMap } from 'ng-dynamic-component';

@Component({
  selector: 'my-component',
  template: `
    <ndc-dynamic
      [ndcDynamicComponent]="component"
      [ndcDynamicAttributes]="attrs"
    ></ndc-dynamic>
  `,
})
class MyComponent {
  component = MyDynamicComponent1;
  attrs: AttributesMap = {
    'my-attribute': 'attribute-value',
    class: 'some classes',
  };
}

Remember that attributes values are always strings (while inputs can be any value). So to have better type safety you can use AttributesMap interface for your attributes maps.

Also you can use ngComponentOutlet and ndcDynamicAttributes with * syntax:

import { AttributesMap } from 'ng-dynamic-component';

@Component({
  selector: 'my-component',
  template: `
    <ng-container
      *ngComponentOutlet="component; ndcDynamicAttributes: attrs"
    ></ng-container>
  `,
})
class MyComponent {
  component = MyDynamicComponent1;
  attrs: AttributesMap = {
    'my-attribute': 'attribute-value',
    class: 'some classes',
  };
}

Standalone API

Since v10.7.0

You can use standalone API to pass dynamic inputs/outputs using DynamicAttributesDirective with DynamicComponent or ngComponentOutlet:

import { DynamicAttributesDirective, DynamicComponent } from 'ng-dynamic-component';

@Component({
  selector: 'my-component',
  template: `
    <ndc-dynamic
      [ndcDynamicComponent]="component"
      [ndcDynamicAttributes]="attrs"
    ></ndc-dynamic>
  `,
  imports: [DynamicAttributesDirective, DynamicComponent]
})
class MyComponent {
  component = MyDynamicComponent1;
  attrs: AttributesMap = {...};
}

Directives (experimental)

Since v3.1.0 you can now declaratively set directives, via ndcDynamicDirectives.

NOTE: There is a known issue with OnChanges hook not beign triggered on dynamic directives since this part of functionality has been removed from the core as Angular now supports this out of the box for dynamic components.

In dynamic directives queries like @ContentChild and host decorators like @HostBinding will not work due to involved complexity required to implement it (but PRs are welcome!).

Import module DynamicDirectivesModule and then in template:

import { dynamicDirectiveDef } from 'ng-dynamic-component';

@Component({
  selector: 'my-component',
  template: `
    <ng-container
      [ngComponentOutlet]="component"
      [ndcDynamicDirectives]="dirs"
    ></ng-container>
  `,
})
class MyComponent {
  component = MyDynamicComponent1;
  dirs = [dynamicDirectiveDef(MyDirective)];
}

It's also possible to bind inputs and outputs to every dynamic directive:

import { dynamicDirectiveDef } from 'ng-dynamic-component';

@Component({
  selector: 'my-component',
  template: `
    <ng-container
      [ngComponentOutlet]="component"
      [ndcDynamicDirectives]="dirs"
    ></ng-container>
  `,
})
class MyComponent {
  component = MyDynamicComponent1;
  directiveInputs = { prop1: 'value' };
  directiveOutputs = { output1: (evt) => this.doSomeStuff(evt) };
  dirs = [
    dynamicDirectiveDef(
      MyDirective,
      this.directiveInputs,
      this.directiveOutputs,
    ),
  ];
}

To change inputs, just update the object:

class MyComponent {
  updateDirectiveInput() {
    this.directiveInputs.prop1 = 'new value';
  }
}

You can have multiple directives applied to same dynamic component (only one directive by same type):

import { dynamicDirectiveDef } from 'ng-dynamic-component';

@Component({
  selector: 'my-component',
  template: `
    <ng-container
      [ngComponentOutlet]="component"
      [ndcDynamicDirectives]="dirs"
    ></ng-container>
  `,
})
class MyComponent {
  component = MyDynamicComponent1;
  dirs = [
    dynamicDirectiveDef(MyDirective1),
    dynamicDirectiveDef(MyDirective2),
    dynamicDirectiveDef(MyDirective3),
    dynamicDirectiveDef(MyDirective1), // This will be ignored because MyDirective1 already applied above
  ];
}

Standalone API

Since v10.7.0

You can use standalone API to pass dynamic inputs/outputs using DynamicDirectivesDirective with DynamicComponent or ngComponentOutlet:

import { DynamicDirectivesDirective, DynamicComponent } from 'ng-dynamic-component';

@Component({
  selector: 'my-component',
  template: `
    <ng-container
      [ngComponentOutlet]="component"
      [ndcDynamicDirectives]="dirs"
    ></ng-container>
  `,
  imports: [DynamicDirectivesDirective, DynamicComponent]
})
class MyComponent {
  component = MyDynamicComponent1;
  dirs = [...];
}

Extra

You can have more advanced stuff over your dynamically rendered components like setting custom injector ([ndcDynamicInjector]) or providing additional/overriding providers ([ndcDynamicProviders]) or both simultaneously or projecting nodes ([ndcDynamicContent]).

Since v10.6.0: You can provide custom NgModuleRef ([ndcDynamicNgModuleRef]) or EnvironmentInjector ([ndcDynamicEnvironmentInjector]) for your dynamic component.


NOTE: In practice functionality of this library is split in two pieces:

  • one - component (ndc-dynamic) that is responsible for instantiating and rendering of dynamic components;
  • two - directive (ndcDynamic also bound to ndc-dynamic) that is responsible for carrying inputs/outputs to/from dynamic component by the help of so called DynamicComponentInjector.

Thanks to this separation you are able to connect inputs/outputs and life-cycle hooks to different mechanisms of injecting dynamic components by implementing DynamicComponentInjector and providing it via DynamicComponentInjectorToken in DI.

It was done to be able to reuse NgComponentOutlet added in Angular 4-beta.3.

To see example of how to implement custom component injector - see ComponentOutletInjectorDirective that is used to integrate NgComponentOutlet directive with inputs/outputs.

Contributing

You are welcome to contribute to this project. Simply follow the contribution guide.

License

MIT Β© Alex Malkevich

ng-dynamic-component's People

Contributors

ajafff avatar bmarti44 avatar chriswhite199 avatar dependabot[bot] avatar greenkeeper[bot] avatar gund avatar hpawe01 avatar jerousseau avatar kamilkisiela avatar mcanfield avatar mohamedaymenkarmous avatar msgoloborodov avatar pxyup avatar semantic-release-bot avatar shadowmax31 avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ng-dynamic-component's Issues

An in-range update of @angular/compiler is breaking the build 🚨

Version 4.2.3 of @angular/compiler just got published.

Branch Build failing 🚨
Dependency @angular/compiler
Current Version 4.2.2
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/compiler is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of @angular/core is breaking the build 🚨

Version 4.2.4 of @angular/core just got published.

Branch Build failing 🚨
Dependency @angular/core
Current Version 4.2.3
Type peerDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/core is β€œonly” a peerDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

can't bind to ndcDynamicComponent

Hi,

I'm trying to use this but I get the following error
Uncaught (in promise): Error: Template parse errors: Can't bind to 'ndcDynamicComponent' since it isn't a known property of 'ndc-dynamic'.

I've imported this in app.module.ts along with components I'd like to use.
DynamicModule.withComponents([DateAnswerComponent,TextAnswerComponent]).

I'm using it with ionic 3 if that matters.

could anybody help me with this?

many thanks

Calling function 'DynamicModule', function calls are not supported

Hi everyone!

i'm trying to use ng-dynamic-component in my app,
I follow the instructions in github, to use it and that error show

ERROR in Error: Error encountered resolving symbol values statically. Calling function 'DynamicModule', function calls are not supported. Consider replacing the function or lambda wi th a reference to an exported function, resolving symbol GridModule in C:/src/MyApp/src/app/pages/grid/grid.module.ts, resolving symbol GridModule in C:/src/MyApp/src/app/pages/grid/grid.module.ts at syntaxError (C:\src\MyApp\node_modules\@angular\compiler\bundles\compiler.umd.js:1729:34) at simplifyInContext (C:\src\MyApp\node_modules\@angular\compiler\bundles\compiler.umd.js:24979:23) at StaticReflector.simplify (C:\src\MyApp\node_modules\@angular\compiler\bundles\compiler.umd.js:24991:13) at StaticReflector.annotations (C:\src\MyApp\node_modules\@angular\compiler\bundles\compiler.umd.js:24418:41) at _getNgModuleMetadata (C:\src\MyApp\node_modules\@angular\compiler-cli\src\ngtools_impl.js:138:31) at _extractLazyRoutesFromStaticModule (C:\src\MyApp\node_modules\@angular\compiler-cli\src\ngtools_impl.js:109:26) at includeLazyRouteAndSubRoutes (C:\src\MyApp\node_modules\@angular\compiler-cli\src\ngtools_impl.js:66:25) at Array.reduce (native) at includeLazyRouteAndSubRoutes (C:\src\MyApp\node_modules\@angular\compiler-cli\src\ngtools_impl.js:67:26) at Array.reduce (native) at Object.listLazyRoutesOfModule (C:\src\MyApp\node_modules\@angular\compiler-cli\src\ngtools_impl.js:54:36) at Function.NgTools_InternalApi_NG_2.listLazyRoutes (C:\src\MyApp\node_modules\@angular\compiler-cli\src\ngtools_api.js:91:39) at AotPlugin._getLazyRoutesFromNgtools (C:\src\MyApp\node_modules\@ngtools\webpack\src\plugin.js:207:44) at _donePromise.Promise.resolve.then.then.then.then.then (C:\src\MyApp\node_modules\@ngtools\webpack\src\plugin.js:443:24) at <anonymous> at process._tickCallback (internal/process/next_tick.js:169:7)

Angular Versions:

@angular/cli: 1.4.3
node: 8.1.2
os: win32 x64
@angular/animations: 4.4.6
@angular/cdk: 2.0.0-beta.11
@angular/common: 4.4.6
@angular/compiler: 4.4.6
@angular/core: 4.4.6
@angular/forms: 4.4.6
@angular/http: 4.4.6
@angular/material: 2.0.0-beta.11
@angular/platform-browser: 4.4.6
@angular/platform-browser-dynamic: 4.4.6
@angular/router: 4.4.6
@angular/cli: 1.4.3
@angular/compiler-cli: 4.4.6
typescript: 2.6.1

ng-dynamic-component version use : ^1.0.0

Any ideas???

An in-range update of @angular/compiler is breaking the build 🚨

Version 4.1.3 of @angular/compiler just got published.

Branch Build failing 🚨
Dependency @angular/compiler
Current Version 4.1.2
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/compiler is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

tslib dependency

Hi @gund,
Quick question...
DO you actually use tslib in your library?? You added as dependency and I just noticed a warning about the missing dependency. However, even if I don't add the dependency, my app still works fine with your library version 2.0.3.

Is this really required?

An in-range update of tslint is breaking the build 🚨

Version 5.3.0 of tslint just got published.

Branch Build failing 🚨
Dependency tslint
Current Version 5.2.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As tslint is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Release Notes v5.3.0

This change may require a change to tslint.json

πŸŽ‰ Notable features & enhancements

Thanks to our contributors!

  • Andy Hanson
  • Klaus Meinhardt
  • Martin Probst
  • Filipe Silva
  • walkerburgin
  • RenΓ© Scheibe
Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Upgrade to version 2.1.0 breaks

Hi,

I was updating the packages from my solution and when upgrading from 2.0.3 to 2.1.0 of your library, all of sudden my screen stopped working.

I had a dynamic form that receives the framework type at the creation of the module and I'm using your library to abstract the dynamic injection of the component

private _collectChangesFromDiffer(differ: any): SimpleChanges {
    const changes = {} as SimpleChanges;

    // It's breaking here! It seems like the differ is null or undefined, causing the loop to break.
    differ.forEachItem((record: KeyValueChangeRecordAny) =>
      changes[record.key] = new CustomSimpleChange(record.previousValue, record.currentValue, false));

    differ.forEachAddedItem((record: KeyValueChangeRecordAny) =>
      changes[record.key].previousValue = UNINITIALIZED);

    return this._resolveChanges(changes);
  }

before (v.2.0.3) :

    if (inputsChanges) {
      const isNotFirstChange = !!this._lastInputChanges;
      this._lastInputChanges = this._collectChangesFromDiffer(inputsChanges);

      if (isNotFirstChange) {
        this.updateInputs();
      }
    }

Current:

    if (inputsChanges) {
      const isNotFirstChange = !!this._lastInputChanges;
      this._updateInputChanges(inputsChanges);

      if (isNotFirstChange) {
        this.updateInputs();
      }
    }

Can you please have a look? It seems the caller of this function changed and something within the new routine is not happy. Possibly due to the fact the _collectChangesFromDiffer() is called twice. One within the ngOnChanges and then on ngOnCheck.

Access to component reference

Hello
I've read the documentation but there is nothing there about getting access to the dynamic component reference...can this be done and if so how?
thanks
Ross

An in-range update of uglifyjs is breaking the build 🚨

Version 2.4.11 of uglifyjs just got published.

Branch Build failing 🚨
Dependency uglifyjs
Current Version 2.4.10
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As uglifyjs is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of @angular/compiler-cli is breaking the build 🚨

Version 4.2.2 of @angular/compiler-cli just got published.

Branch Build failing 🚨
Dependency @angular/compiler-cli
Current Version 4.2.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/compiler-cli is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Failed to compile: Can't resolve 'tslib'

Hello,
your Package looks promising, but I cannot get it to work.
When I use this package with the current angular version (either 4.0.0 or 4.0.1), I get the following error message:

ERROR in ./~/ng-dynamic-component/dist/dynamic/custom-simple-change.js
Module not found: Error: Can't resolve 'tslib' in '/home/vagrant/component-test/node_modules/ng-dynamic-component/dist/dynamic'
 @ ./~/ng-dynamic-component/dist/dynamic/custom-simple-change.js 1:0-33
 @ ./~/ng-dynamic-component/dist/dynamic/dynamic.directive.js
 @ ./~/ng-dynamic-component/dist/dynamic/index.js
 @ ./~/ng-dynamic-component/dist/index.js
 @ ./src/app/app.module.ts
 @ ./src/main.ts
 @ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts

Steps to reproduce using Angular CLI:

  1. ng new component-test
  2. cd component-test
  3. npm install --save ng-dynamic-component
  4. In src/app/app.module.ts add import-statement (import { DynamicModule } from 'ng-dynamic-component';) and module in imports-array.
  5. ng serve

Cheers

ngModel compability

Is it possible to use ngModel together with the component provided by this module? Or is it only inputs/ouputs at the moment?

An in-range update of @angular/core is breaking the build 🚨

Version 4.2.2 of @angular/core just got published.

Branch Build failing 🚨
Dependency @angular/core
Current Version 4.2.1
Type peerDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/core is β€œonly” a peerDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Doesn't work with ngComponentOutlet

Any ideas why this won't work?

<ng-container *ngIf="item?.component; else elseBlock">
  <ng-container *ngComponentOutlet="item.component"
                [ndcDynamicInputs]="item.inputs">
  </ng-container>
</ng-container>

Works fine if I use <ndc-dynamic> and [ndcDynamicComponent]. I also tried with a div instead of ng-container, but not luck...

Destruction of dynamic components

Hi Alex !

Today I'm wondering how the destruction of the dynamic components are handled; so I know when ngOnDestroy will be called.
More than that, I would need a way to be able to force the destruction of a dynamic component: I have a panel in which I inject a component dynamically via your tool, and then I hide the panel from the interface, but what I would actually need is to effectively destroy the dynamic component (I want to keep the panel alive).

Thank you!

Calling function from parent component

How would I go about calling a function from the parent, something like this :

@Component({
    template: `<button (click)="doStuff()">Do something</button>
               <ng-container *ngComponentOutlet="dynamicComponent;
                              ndcDynamicInputs: inputs;
                              ndcDynamicOutputs: outputs"></ng-container>`
})
export class ParentComponent {
     dynamicComponent = ChildComponent1;
     inputs = {};
     outputs = {};

     doStuff = () => {
        //Do stuff

        //Call child component doStuff function
     }
}

@Component({ ... })
export class ChildComponent1{
    doStuff = () => {  ...  }
}

One workaround I can think of, would be by changing an input value, thus triggering Angular change detection and implementing ngOnChanges in the child component but I don't think it's really nice.

An in-range update of @angular/compiler-cli is breaking the build 🚨

Version 4.2.4 of @angular/compiler-cli just got published.

Branch Build failing 🚨
Dependency @angular/compiler-cli
Current Version 4.2.3
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/compiler-cli is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

'TypeError: Cannot convert undefined or null to object' when inputs or outputs are not defined

Scenario:

An array of mixed types representing components to render with ndc-dynamic may not contain an inputs/outputs key. As a result dynamic directive will throw TypeError: Cannot convert undefined or null to object:

let cards = [
  { 
    'component': SpadesCard,
    'inputs': { value: 'A' },
    'outputs': { onDraw: message => console.log(message)}
  },
  { 
    'component': HeartsCard,
    'inputs': { value: '2' },
    'outputs': { onDraw: message => console.log(message)}
  },
  { 
    'component': BlankCard
  },
  ...
];

// Template
<ng-container *ngFor="let card of cards">
  <ndc-dynamic [ndcDynamicComponent]="card.component"
      [ndcDynamicInputs]="card.inputs"
      [ndcDynamicOutputs]="card.outputs"
    ></ndc-dynamic>
</ng-container>

// Results in -->
// TypeError: Cannot convert undefined or null to object

Ideally the calling code doesn't need to provide an empty object to the ndcDynamic* directives. The directive code could be made robust enough to handle inputs/outputs that are not defined.

How to access inputs in the dynamic component passed from the creating component

Hiya! Quick questions, the documentation only shows how to set inputs/outputs, but not how to use them on the dynamically rendered component. For example given the following component:

@Component({
  selector: 'my-component',
  template: `<ndc-dynamic [ndcDynamicComponent]="component"
                          [ndcDynamicInputs]="inputs"
                          [ndcDynamicOutputs]="outputs"
                          ></ndc-dynamic>`
})
class MyComponent {
  component = MyDynamicComponent1;
  inputs = {
    hello: 'world',
    something: () => 'can be really complex'
  };
  outputs = {
    onSomething: (type) => alert(type)
  }
}

How would I access the input values from within MyDynamicComponent1? Or am I misunderstanding the purpose of the inputs/outputs?

@Component({
  selector: 'my-dynamic-component1',
  template: `<div>Hello, {{inputs.hello}}!</div>`
})
class MyDynamicComponent1 {
 // How can I get a hold of the inputs passed from "my-component"? For example, I'd like to access the "inputs.hello".
...
}

Rxjs 6 support

Any plans on supporting Rxjs 6? Atm i get errors when it tries to include "rxjs/Subject" which should be "rxjs" and rxjs/add/operator/takeUntil which should be "rxjs/operators"

Not able to build with AOT on Angular 5 and ndc 2.0.2

Thanks for the work on resolving #69 . That seems to have solved the problem after updating to angular 5. But now when I try to build a production version of my app (with aot), I get the following error:

ERROR in Error: Error encountered resolving symbol values statically. Calling function 'DynamicModule', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol DashModule in /var/www/genesis/client/src/app/dash/dash.module.ts, resolving symbol DashModule in /var/www/genesis/client/src/app/dash/dash.module.ts

This is the line the module file that causes the error:

DynamicModule.withComponents([ DashletFavoriteComponent, DashletRecentComponent, DashletTrendingComponent ])

Am I missing something here?

"ng serve" works fine. So does "ng build" with aot false. Also the previous versions (angular 4 + ndc 1.x) used to work fine with aot enabled.

An in-range update of @angular/compiler is breaking the build 🚨

Version 4.2.5 of @angular/compiler just got published.

Branch Build failing 🚨
Dependency @angular/compiler
Current Version 4.2.4
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/compiler is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

@Inputs with ngComponentOutlet

Apparently the inputs are undefined with this syntax.

`<div *ngComponentOutlet="component"
                   [ndcDynamicInputs]="inputs"
                   [ndcDynamicOutputs]="outputs"
                   ></div>`

But It's working with <ndc-dynamic>

An in-range update of @angular/compiler is breaking the build 🚨

Version 4.1.2 of @angular/compiler just got published.

Branch Build failing 🚨
Dependency @angular/compiler
Current Version 4.1.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/compiler is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Change component on the fly

Say you had a select. And onChange you call a function that will update the referenced component.
So, depending on the selection you want to load one component or another.

Is this possible? Some workaround? tried to assign something else to my variable currentForm but didn't work.

<ndc-dynamic [ndcDynamicComponent]="currentForm"></ndc-dynamic>

Passing node content via ndcDynamicContent

Hi !
Inputs and outputs work great on my dynanic elements! However, I can't get to pass the content of the node to the dynamic component.

Here's my context: I've developped a TrialComponent, aimed at trying different look&feel of various component, by switching them dynamically (via a button next to the TrialComponent). The simplified structure is:

Application component offering some trial on some components

...
<comp-trial 
  [inputs]="{ title:'...' }"
  [outputs]="{ click: onClick }"
>
	This is some content for the dynamic components
</comp-trial>
...

Trial Component

@Component({
	selector: 'comp-trial',
	template: '
	  <ndc-dynamic 
		[ndcDynamicComponent]="dynamicComponent"
		[ndcDynamicInputs]="inputs"
		[ndcDynamicOutputs]="outputs"
	  >
	  </ndc-dynamic>
	'
})
export class TrialComponent {
  dynamicComponent; // the component to insert dynamically (management of this var is not developed here)
  @Input() inputs: Array<any>;
  @Input() outputs: Array<any>;
}

One of the dynamic component

@Component({
  selector: 'dyn-comp1',
  template: '
	<div>{{ title }}</div>
	<div class="content"> ...? </div>
  '
})
export class ExpandablePanel1Component extends ExpandablePanel {
   @Input() title;
   @Input() items;
   @Output() click;
}

I've tried to use ndcDynamicContent on my TrialComponent, but couldn't get to make it work.

Any advice to pass some node content to the dynamic components?

An in-range update of @angular/compiler is breaking the build 🚨

Version 4.2.4 of @angular/compiler just got published.

Branch Build failing 🚨
Dependency @angular/compiler
Current Version 4.2.3
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/compiler is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

injecting an id dynamically

Hi,
Your offering is very interesting. I am just trying to use it. I came upon the following issue as explained below:

I have the following component I would like to dynamically insert in my SPA - LumpCompnent - that has the following declartive definition:

<epimss-lump #lumpCmpRef></epimss-lump>

How do I insert the angular4 id #lumpCmpRef dynamically using ng-dynamic-component?

Thanks

Looping dynamic component changes order

I am trying to loop like following code but the order of sections is not retained if same component type is used. Components with similar type all gets added at the end.

<div data-paroller-factor="0.3" *ngFor="let section of sections; let i = index"> <ndc-dynamic [ndcDynamicComponent]="section.component" [ndcDynamicInputs]="section.componentData"></ndc-dynamic> </div>

Providers and Services

Hi,

I was wondering if you could provide an example of how to use ndcDynamicProviders to add extra providers to the dynamic loading. I'm trying to load a component which requires a service but I get an error "Can't resolve all parameters for TabComponent: (?)". The service is local to the module that TabComponent is defined in (and the dynamic host resides in the same module) and, if I statically load the component then it works fine.

I'm assuming ndcDynamicProviders should be an array of service type names or something?

Cheers,
Chris

strange focus behaviour

Please take a look at this example

AppComponent dinamically insert InputComponent, each InputComponent dinamically insert LabelComponent (before the input), SvuotaComponent (just a button immediately after the input field, that empty the input) and ErrorComponent (after the button).

Buttons are disabled until input fields are empty. While inputs are empty if you press tab focus works as expected, button are skipped and focus jump to the next input.

If you fill an input field and the focus is on the input filled, you need to press tab two times in order to focus on button, and, even stranger, you need to click two times on button for the click event to be managed.

If I 'statically' put a button after input tab and click work as expected.

Compiling with AoT not working

I've been using your library for a little while now to great effect however when I try to compile my Angular application using AoT I get Error encountered resolving symbol values statically. Calling function 'DynamicModule', function calls are not supported. I see that your library does produce the expected .metadata.json files so I'm not sure what's wrong. I have tried using the standard angular-cli seed application for testing and still see the issue.

If AoT support is not working or not planned It might be nice to put a note about that on the readme.

Cannot find Dynamic Module

Hello,

I used you angular 4 component and it works just fine with an angular 4 cli project . But we have an angular cli 2 application and app,module.ts throws a compile time error of 'cannot load module Dynamic Module' I am using version ^0.0.1 as per your instructions. Please let me know how to get around this..

ngOnChanges called twice

Hi,

When we change the component on the fly, the ngOnChanges of the new component is called twice, first time with the inputs we have passed to the new component ( firstChange: true and no previousValue) and a second time with in previousValue the value of the old component.
Any idea to avoid this ?

Thanks

Plnkr example to reproduce : https://plnkr.co/edit/uM7FzOmI4wNPE4F8WtFR

An in-range update of rxjs is breaking the build 🚨

Version 5.3.3 of rxjs just got published.

Branch Build failing 🚨
Dependency rxjs
Current Version 5.3.2
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As rxjs is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details,- βœ… codecov/project 100% remains the same compared to f98d834 Details,- βœ… codecov/patch Coverage not affected when comparing f98d834...dbddf6c Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of @angular/compiler-cli is breaking the build 🚨

Version 4.2.5 of @angular/compiler-cli just got published.

Branch Build failing 🚨
Dependency @angular/compiler-cli
Current Version 4.2.4
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/compiler-cli is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

AppModule Providers not working inside ndc-dynamic

I have been trying to pass on the common instances of the AppModule Providers inside ndc-dynamic but unsuccessful so far. Here are the things I have tried

(1) without [ndcDynamicProviders], it seems the components are getting 'undefined' object instances of the services

(2) with [ndcDynamicProviders], it seems new object instances of the services getting created, which are different to the object instances available via components constructors under AppModule.

What I require is the exact object instances that are available inside AppModule.

Some help would be really appreciated.

Example usage within for loops

Is there an example for usages of this module within an *ngFor?

For example:

        <ng-container *ngFor="let obj of parent.controls[objectType].controls; let i=index" [formGroupName]="i">
            <ndc-dynamic [ndcDynamicComponent]="objectComponentType" [object]="obj" [parent]="parent" (remove)="removeRow(i)"></ndc-dynamic>
        </ng-container>

How to create new instance of dynamic component

Hi,

It's great module to use for dynamic component rendering. However facing issues in data binding. Same instance of component being render in DOM. If I am trying to insert a type of component having values inserted from response object, same values are being binded previously added dynamic component.

Is there a way to create new instance of it and then add to the DOM.

Thanks in advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.