angular2-components

How to use ResolveComponentFactory() but with a string as a key

你。 提交于 2019-11-26 17:48:03
问题 what I'm trying to do: Use something similar to the "resolveComponentFactory()", but with a 'string' identifier to get Component Factories. Once obtained, start leverage the "createComponent(Factory)" method. Plnkr Example -> enter link description here In the example, you will see the "AddItem" method addItem(componentName:string):void{ let compFactory: ComponentFactory; switch(componentName){ case "image": compFactory = this.compFactoryResolver.resolveComponentFactory(PictureBoxWidget);

How to call another components function in angular2

爱⌒轻易说出口 提交于 2019-11-26 17:00:55
I have two components as follow and I want to call a function from another component. Both components are included in the third parent component using directive. Component 1: @component( selector:'com1' ) export class com1{ function1(){...} } Component 2: @component( selector:'com2' ) export class com2{ function2(){... // i want to call function 1 from com1 here } } I've tried using @input and @output but I don't understand exactly how to use it and how to call that function, can anyone help? Günter Zöchbauer If com1 and com2 are siblings you can use @component({ selector:'com1', }) export

Share data between components using a service in Angular2

喜欢而已 提交于 2019-11-26 16:16:01
问题 I am developing an application using angular2. I have a scenario where I need to pass complex data (array of objects) from one component to another component(they are not parent-child, they are two separate components) while routing(using router.navigate()). I have googled this and most of the results describe the scenario of components that are parent-child. I have gone through the results and found these ways to pass the data. 1) Create Shared Service 2) Pass as route parameters 2nd

How to call component method from service? (angular2)

狂风中的少年 提交于 2019-11-26 16:01:05
问题 I want to create service, which can interact with one component. All another components in my app, should be able to call this service, and this service should interact with this component. How to call component method from service? @Component({ selector:'component' }) export class Component{ function2(){ // How call it? } } From this servive? @Injectable() export class Service { callComponentsMethod() { //From this place?; } } 回答1: Interaction between components can be indeed achieved using

How to pass an expression to a component as an input in Angular2?

让人想犯罪 __ 提交于 2019-11-26 13:54:18
问题 I need to pass an expression to a component that will be evaluated inside an component's template. For example, component: @Component({ selector: 'app-my-component', ... }) export class MyComponent { @Input items: MyClass; @Input expression: String; ... } with component's template: <div *ngFor="let item of items"> {{expression}} </div> Usage of MyComponent: <app-my-component [items]="listOfItems" [expression]="'[item.id] item.name'"> </app-my-component> As there will be more than one input, I

ng2 - dynamically creating a component based on a template

自闭症网瘾萝莉.ら 提交于 2019-11-26 09:01:55
问题 I\'ve been looking at the Angular 2 APIs for ComponentResolver and DynamicComponentResolver for creating dynamic components, but I have something different in mind than those APIs offer. Is there any way in NG2 to create a component based on a string of its class name? For example, Im building a configurable charts dashboard. Each user\'s layout is stored in the database, stating they want 2x line charts here, 3x bar charts there, etc. When I load this data as json it looks something like:

How to call another components function in angular2

假如想象 提交于 2019-11-26 04:32:49
问题 I have two components as follows and I want to call a function from another component. Both components are included in the third parent component using directive. Component 1: @component( selector:\'com1\' ) export class com1{ function1(){...} } Component 2: @component( selector:\'com2\' ) export class com2{ function2(){... // i want to call function 1 from com1 here } } I\'ve tried using @input and @output but I don\'t understand exactly how to use it and how to call that function, can