You can register a custom ControlValueAccessor like this in providers (the bindings attribute is deprecated) of the corresponding directive:
const CUSTOM_VALUE_ACCESSOR = CONST_EXPR(new Provider( NG_VALUE_ACCESSOR, {useExisting: forwardRef(() => TagsValueAccessor), multi: true})); @Directive({ selector: 'tags', host: {'(labelsChange)': 'onChange($event)'}, providers: [CUSTOM_VALUE_ACCESSOR] }) export class TagsValueAccessor implements ControlValueAccessor { (...) }
Then this accessor is automatically selected when you use ngModel and / or ngFormControl for the component with the tags selector:
@Component({ (...) directives: [ TagsComponent, TagsValueAccessor ], template: ` <tags [(ngModel)]="company.labels" [ngFormControl]="companyForm.controls.labels"></tags> ` }) export class DetailsComponent { (...) }
There is a complete sample in this question: Angular 2 user input form .
Hope this helps you, Thierry
Thierry templier
source share