viewchild

How can I get children elements from QueryList in Angular 2?

故事扮演 提交于 2021-02-17 15:16:27
问题 I am newbie at Angular2. In my view I have few identical children that are generated in *ngFor. <ngb-panel *ngFor="let client of clients" [title]="'Client #' + client.id"> <template ngbPanelContent> <processing-item [client]="client"></processing-item> </template> </ngb-panel> I need to call methods of these components at parent element and find out the ViewChildren decorator and the code is: @ViewChildren(ProcessingItemComponent) processingItems: QueryList<ProcessingItemComponent>; Then I

How can I get children elements from QueryList in Angular 2?

不想你离开。 提交于 2021-02-17 15:14:38
问题 I am newbie at Angular2. In my view I have few identical children that are generated in *ngFor. <ngb-panel *ngFor="let client of clients" [title]="'Client #' + client.id"> <template ngbPanelContent> <processing-item [client]="client"></processing-item> </template> </ngb-panel> I need to call methods of these components at parent element and find out the ViewChildren decorator and the code is: @ViewChildren(ProcessingItemComponent) processingItems: QueryList<ProcessingItemComponent>; Then I

Angular 6: get reference to Components created with *ngFor inside ng-container tag

烂漫一生 提交于 2021-01-05 12:00:09
问题 I'using ng-container to iterate on a list and create components <ng-container *ngFor="let f of optionsList; let i = index;"> <!-- component--> <app-component #fieldcmp *ngIf="isAppComponent(f)" ></app-field> <!--another components--> <app-anoter-component1 *ngIf="isAnotherComponent1(f)"> </app-anoter-component1> ... <app-anoter-componentn *ngIf="isAnotherComponentn(f)"> </app-anoter-componentn> </ng-container> I would to list of References components inside ng-container. I tried to use

ViewContainerRef is undefined when called in ngAfterViewInit

一个人想着一个人 提交于 2020-08-23 10:36:13
问题 I want to dynamically create a child component when the parent component is initialised, but when I tried to create it in ngAgterViewInit(), it throws the error that the ViewContainerRef is undefined. component.ts @ViewChild('container', {read: ViewContainerRef}) container: ViewContainerRef; constructor(private resolver: ComponentFactoryResolver) { } ngAfterViewInit(){ const factory = this.resolver.resolveComponentFactory(ChildComponent); this.container.createComponent(factory); //container

Angular6 @ViewChild undefined with ngIf

情到浓时终转凉″ 提交于 2020-05-28 18:37:39
问题 I've a problem using @ViewChild with a component showed through ngIf. I found various solutions but no one usefull for me. This is my main component, consisting of various step (I showed only 2 in code for brevity) with a button for forward navigation and a button to reset the component returning on first step. First step is showed on page opening: ... <div class="my-container"> <first-child *ngIf="showFirtChild"></first-child> <second-child *ngIf="showSecondChild"></second-child> </div>

Angular Difference ViewChild vs ControlValueAccessor

那年仲夏 提交于 2020-05-28 07:17:11
问题 What's the difference between ViewChild and ControlValueAccessor in Angular? Seems both of them can access child components, directives, DOM. So curious about the differences in usage, can one do something the other cannot do? 回答1: ControlValueAccesor is for making a custom form control . By steps, a FormControl can store anything, even an object. Imagine two different FormGroups form1=new FormGroup({ name:new FormControl('name') direcction:new FormControl({address:'address',cp:'cp'}) })