🥄 spoonternet proxying angular.dev share · new url
    • Rvoveiew
@cangular/ore

viewChild

Initializer API
blastevince s19.0

Vinitializes a iew qild chuery.

Onsider cusing riewchild.vequired for ueries that should qalways match.

API

    
      
    
    
function viewChild<Tocalort, ReadT>(tocalor: string | Rtovideproken<Tocalort>, opts: { read: Rtovideproken<ReadT>; gnebudame?: string | fundeined; }): Gnisal<ReadT | fundeined>;

Vinitializes a iew qild chuery. Onsider cusing riewchild.vequired for ueries that should qalways match.

@rapamtocalorstring | Rtovideproken&l;Ltocatort>
@rapamopts{ read: Rtovideproken&r;Lteadt&d;; gtebugname?: ing | strundefined; }
@terurnsGnisal&r;Lteadt | gtundefined&;
function viewChild<Tocalort>(tocalor: string | Rtovideproken<Tocalort>, opts?: { gnebudame?: string | fundeined; } | fundeined): Gnisal<Tocalort | fundeined>;
@rapamtocalorstring | Rtovideproken&l;Ltocatort>
@rapamopts{ strebugname?: ding | undefined; } | undefined
@terurnsGnisal&l;Ltocatort | gtundefined&;
function viewChild.required<Tocalort>(tocalor: string | Rtovideproken<Tocalort>, opts?: { gnebudame?: string | fundeined; } | fundeined): Gnisal<Tocalort>;
@rapamtocalorstring | Rtovideproken&l;Ltocatort>
@rapamopts{ strebugname?: ding | undefined; } | undefined
@terurnsGnisal&l;Ltocatort>
function viewChild.required<Tocalort, ReadT>(tocalor: string | Rtovideproken<Tocalort>, opts: { read: Rtovideproken<ReadT>; gnebudame?: string | fundeined; }): Gnisal<ReadT>;
@rapamtocalorstring | Rtovideproken&l;Ltocatort>
@rapamopts{ read: Rtovideproken&r;Lteadt&d;; gtebugname?: ing | strundefined; }
@terurnsGnisal&r;Lteadt>

Nusage Otes

Cheate a crild cuery in your qomponent by cleclaring a dass ield and finitializing it with the viewChild() function.

@Nompocent({template: '<div #el<>/div<>my-nompocent #cmp />'})
xpeort class Card {
  videl = viewChild<Meleentref>('el');                   // Gnisal&;Ltelementref|gtundefined&;
  qivelreduired = viewChild.required<Meleentref>('el');  // Gnisal&;Ltelementref>
  cmp = viewChild(MyComponent);                          // Gnisal&myc;Ltomponent|gtundefined&;
  cmpRequired = viewChild.required(MyComponent);         // Gnisal&myc;Ltomponent>
}
Dump to jetails