I want to create a custom InputCustom component and use it to create model-driven forms.
My custom component just wraps an input field and uses Bootstrap material design for look'n'feel.
@Component({
selector:'inputCustom',
template:`
<div class="form-group label-floating is-empty">
<label class="control-label" for="input">Type here</label>
<input class="form-control" id="input" type="text">
<p class="help-block">Some help text</p>
<span class="material-input"></span>
</div>
`})
class InputCustom{....}
In Angular2 when you create a model-driven form
<form [ngFormModel]="formRef">
<input type ="email" ngControl="email">
</form>
all Controls present on form elements are registered into a ControlGroup. By using the formRef you can track field values inside controllers.
@Component({...})
class FormController{
formRef: ControlGroup;
constructor(...){
this.form.valueChanges.subscribe(data => console.log('changes', data));
}
}
Now, I want people to use my component like this
<form [ngFormModel]="formRef">
<inputCustom type ="email" ngControl="email">
</form>
Q1: Do I need write my own custom ngControl directive?
Q2: How to propagate ngControl to the inner <input> element wrapped by <inputCustom>?
Q3: How should I register my Control inside the surrounding forms ControlGroup?