Angular2: child component access parent class variable/function

前端 未结 5 1042
夕颜
夕颜 2020-12-02 11:47

I have a variable in the parent component that might be changed by child, parent will be using this variable in the view and thus has to propagate changes.

i         


        
5条回答
  •  -上瘾入骨i
    2020-12-02 12:31

    The main article in the Angular2 documentation on this subject is :

    https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#parent-to-child

    It covers the following:

    • Pass data from parent to child with input binding

    • Intercept input property changes with a setter

    • Intercept input property changes with ngOnChanges

    • Parent listens for child event

    • Parent interacts with child via a local variable

    • Parent calls a ViewChild

    • Parent and children communicate via a service

提交回复
热议问题