Update parent component property from child component in Angular 2

前端 未结 4 597
北海茫月
北海茫月 2020-11-30 23:44

I\'m using @input to receive a property from parent component in order to activate a CSS class in one of child component\'s element.

I\'m able to receiv

4条回答
  •  被撕碎了的回忆
    2020-11-30 23:56

    Another approach: use rxjs/BehaviorSubject to pass status between different components.
    Here's the plunkr.
    I name subject with a suffix 'Rxx', so the BehaviorSubject for searchStatus will be searchStatusRxx.

    1. initialize it in parent component like searchStatusRxx = new BehaviorSubject(false);,
    2. pass it to child component using @Input
    3. in child template, you do async pipe.
    4. in both parent and child, you do searchStatusRxx.next(value) to change the latest value.

提交回复
热议问题