Update parent component property from child component in Angular 2

前端 未结 4 605
北海茫月
北海茫月 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-12-01 00:14

    Yet another way. Plunkr. What we want is a single source of truth. We can put that in child this time.

    • Init in child: searchStatus = false
    • In parent template, get the instance of child as #as or whatever name.
    • Change searchStatus in parent using #as.searchStatus and in child this.searchStatus.

提交回复
热议问题