Angular 14 calling Child Component method from Parent Component

Shervin Shakibi

I am getting an error when I try to call a childComponent method from the Parent

**Child TS. **

   export class ChildComponent implements OnInit {
     ChildMethod(){
       console.log('test');
     }
     constructor() { }
   }

**Parent Ts **

   @ViewChild(ChildComponent , {static : false}) child!:ChildComponent ;
  
   CallChild(){
       this.child.ChildMethod();
     }

when I call CallChild I get this error Cannot read properties of undefined (reading 'ChildMethod') at GpmainComponent.CallChild (gpmain.component.ts:39:16)

alias1

Try to declare your Child component in constructor.

in Parent.ts:

constructor(private child: ChildComponent) {}

CallChild() {
  this.child.ChildMethod();
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calling a method on Parent Component from Child Component

From Dev

Angular 4 - Calling a parent method from a child component not working

From Dev

react: Calling child component's method from parent component

From Dev

Calling a method in the parent component from a child component using blazor server

From Dev

Calling parent component method from child component written in Jsx Vue

From Dev

Calling parent method from child component not working with callback

From Dev

Calling a method of a parent component from child - React Native

From Dev

Calling parent functions from child component

From

Call child component method from parent class - Angular

From

Angular 4 call parent method in a child component

From Dev

Calling a method from child component in ionic 2

From Dev

Calling a children method of a functional component from parent

From Dev

Call method from parent to child via component

From Dev

Trigger child component method from parent event

From Dev

Vuejs: Access a Parent Method from Child Component

From Dev

Component constructor and Router life-cycle hooks not triggered when calling router.parent.navigate method from child component in Angular2 routing

From Dev

Angular 2 how to emit method in component child to component parent

From Dev

Angular 8: using ViewChild get a method result from a child to parent after that method is invoked in child component

From Dev

Angular access parent variable from child component

From Dev

Update child component from parent in Angular

From Dev

Data Sharing from parent to child component in Angular

From Dev

Child component is not calling parent component function

From Dev

Passing method from parent component to child component in vuejs

From Dev

How to call child component's method from a parent component in React

From Dev

Pass method from parent component to child component in vuejs

From Dev

How can I call method in child component from parent component?

From Dev

Trigger method on parent component from child component - react

From Dev

How to call child component method from parent component with foreach

From Dev

Can't get method to execute on parent component from child component

Related Related

  1. 1

    Calling a method on Parent Component from Child Component

  2. 2

    Angular 4 - Calling a parent method from a child component not working

  3. 3

    react: Calling child component's method from parent component

  4. 4

    Calling a method in the parent component from a child component using blazor server

  5. 5

    Calling parent component method from child component written in Jsx Vue

  6. 6

    Calling parent method from child component not working with callback

  7. 7

    Calling a method of a parent component from child - React Native

  8. 8

    Calling parent functions from child component

  9. 9

    Call child component method from parent class - Angular

  10. 10

    Angular 4 call parent method in a child component

  11. 11

    Calling a method from child component in ionic 2

  12. 12

    Calling a children method of a functional component from parent

  13. 13

    Call method from parent to child via component

  14. 14

    Trigger child component method from parent event

  15. 15

    Vuejs: Access a Parent Method from Child Component

  16. 16

    Component constructor and Router life-cycle hooks not triggered when calling router.parent.navigate method from child component in Angular2 routing

  17. 17

    Angular 2 how to emit method in component child to component parent

  18. 18

    Angular 8: using ViewChild get a method result from a child to parent after that method is invoked in child component

  19. 19

    Angular access parent variable from child component

  20. 20

    Update child component from parent in Angular

  21. 21

    Data Sharing from parent to child component in Angular

  22. 22

    Child component is not calling parent component function

  23. 23

    Passing method from parent component to child component in vuejs

  24. 24

    How to call child component's method from a parent component in React

  25. 25

    Pass method from parent component to child component in vuejs

  26. 26

    How can I call method in child component from parent component?

  27. 27

    Trigger method on parent component from child component - react

  28. 28

    How to call child component method from parent component with foreach

  29. 29

    Can't get method to execute on parent component from child component

HotTag

Archive