Accessing a property in a parent Component

后端 未结 6 704
春和景丽
春和景丽 2020-11-29 23:41

I have a property in a top level Component that is used data from a HTTP source like so (this is in a file called app.ts):

import {UserData} fro         


        
6条回答
  •  再見小時候
    2020-11-30 00:00

    I made a generic component where I need a reference to the parent using it. Here's what I came up with:

    In my component I made an @Input :

    @Input()
    parent: any;
    

    Then In the parent using this component:

     
    

    In the super component I can use any public thing coming from the parent:

    Attributes:

    parent.anyAttribute
    

    Functions :

    parent[myFunction](anyParameter)
    

    and of course private stuff won't be accessible.

提交回复
热议问题