How to call router outlet child component method from parent comonent

前端 未结 10 1970
甜味超标
甜味超标 2020-12-18 19:42

I am new to angular2


    

I have a button in parent component, if

10条回答
  •  [愿得一人]
    2020-12-18 20:01

    You can use a shared service to communicate with components added by the router.

    You can also use the activate event of the Router outlet for the parent to know when a component was added by the router

    Template

    
    

    Component

      onActivate(componentRef){
        componentRef.works();
      }
    

    Child Comp

     works(){
        console.log("works");
      }
    

提交回复
热议问题