viewchild

Angular Difference ViewChild vs ControlValueAccessor

房东的猫 提交于 2020-05-28 07:16:32
问题 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'}) })

Angular Difference ViewChild vs ControlValueAccessor

微笑、不失礼 提交于 2020-05-28 07:16:26
问题 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'}) })

Angular Difference ViewChild vs ControlValueAccessor

我与影子孤独终老i 提交于 2020-05-28 07:15:10
问题 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'}) })

Angular Difference ViewChild vs ControlValueAccessor

核能气质少年 提交于 2020-05-28 07:14:48
问题 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'}) })

Access nth child of ViewChildren Querylist (Angular)

南笙酒味 提交于 2020-03-18 10:50:30
问题 I'm trying to access the nth child of a viewchildren querylist. Below is my TS: @ViewChildren(PopoverDirective) popovers: QueryList<PopoverDirective>; console.log(this.popovers) The console.log shows changes, first, last, length and _results. How can I access the nth child (i.e., 3rd, instead of first)? When I try to do this with _results (i.e., this.popovers._results[2]), I get an error. Thank you. 回答1: There are actually a couple of methods which you can access a particular inside you

@Viewchild can not see matSort

梦想的初衷 提交于 2020-02-02 11:28:12
问题 In my Angular application, my @ViewChild instance is failing to fill HTL matSort. mycomponent.ts: import { MatSort } from '@angular/material'; export class MyClassComponent { @ViewChild(MatSort) sort: MatSort; } ngOnInit() { console.log(this.sort); // undefined } mycomponent.html: <mat-table #table [dataSource]="dataSource" matSort> ....................................................... ....................................................... </mat-table> I need to use sortChange from matSort

ViewChild returns 'undefined' - Angular2

不打扰是莪最后的温柔 提交于 2020-01-24 22:47:12
问题 I'm trying to execute a function of a child component with a push of a button on the parent but for some reason its undefined. Parent: .. com1.html <ng-template #content let-c="close" let-d="dismiss"> <div class="modal-header"> <h4 class="modal-title">Title</h4> </div> <div class="modal-body" style="display: flex; justify-content: center;"> <app-com2 [var1]="value" #traceRef></app-com2> </div> <div class="modal-footer"> <button type="button" class="btn btn-outline-dark" (click)="savePNG()"><i

Angular, get ViewChild / ViewContainerRef from dynamic created Component

♀尐吖头ヾ 提交于 2020-01-03 10:23:09
问题 is there a way to get the ViewContainerRef from a dynamic created component? My dynamic created component has an ngContent element inside, which i want to fill after the dynamic creation. export class Example { @ViewChild('content', { read: ViewContainerRef }) //normal way content: ViewContainerRef; ... ngAfterViewInit(){ let box1=this.content.createComponent(this.boxFactory); box1.instance.title="Dynamic (1)"; // HERE: the box1 has a ng-content area which i want to fill. } } I think about

Angular 4 set the focus in the dynamic generated textbox using viewChildran

大兔子大兔子 提交于 2019-12-24 01:21:21
问题 I have the dynamically generated textbox as below. <tr *ngFor="let item of data; let in=index"> <td> <input #unitNumber type="text" name="workPerformed-workcode-{{in}}" [(ngModel)] = "item.unitnumber" > </td> <td> <!-- Search option is given to chose the unit number----></td> </tr> Here, the search option is given to choose the unit number, if it has been chosen, then the corresponding textbox will be focused on using viewChildran. My try is @ViewChildren('unitNumber') enteredUnitNumbers; //

Unit testing angular 5 component with @ViewChild

半腔热情 提交于 2019-12-23 08:35:26
问题 I am using angular 5.2.0. I have a child component import { Component } from '@angular/core'; @Component({ template: `<div><\div>` }) export class ChildComponent { public childMethod() { ... } } and a parent component which accesses the child via ViewChild import { Component, ViewChild } from '@angular/core'; import { ChildComponent } from 'child.component'; @Component({ template: `<child-component #child><\child-component>` }) export class ParentComponent { @ViewChild('child') public child: