angular2 pass ngModel to a child component

前端 未结 3 1421
再見小時候
再見小時候 2020-12-10 12:47

I have ParentComponent and a ChildComponent, and I need to pass the ngModel in ParentComponent to ChildComponent.

// the below is in ParentComponent template         


        
3条回答
  •  时光取名叫无心
    2020-12-10 13:18

    You need to implement ControlValueAccessor in the child class. It's what defines your component as "having a value" that can be bound to using the angular way.

    Read more about it here: http://blog.thoughtram.io/angular/2016/07/27/custom-form-controls-in-angular-2.html

提交回复
热议问题