Accessing a property in a parent Component

后端 未结 6 691
春和景丽
春和景丽 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:16

    On Angular 6, I access parent properties by injecting the parent via constructor. Not the best solution but it works:

     constructor(@Optional() public parentComponentInjectionObject: ParentComponent){
        // And access like this:
        parentComponentInjectionObject.thePropertyYouWantToAccess;
    }
    

提交回复
热议问题