I need to add a model drive form validation to my custom input component.
I'm not sure how to implement it passing ngControl
to my component.
In my plunkr example http://plnkr.co/edit/QTmxl8ij5Z6E3xKh45hI?p=preview
there are first two input tags which are working and then there is the my-form-input
which should do the same thing as the first two inputs, but using a custom component
<form [ngFormModel]="loginForm">
<p>
<input type="text" ngControl="usernameX" required placeholder="usernameX" /><br>
valid {{usernameX.valid}}
</p>
<p>
<input type="text" ngControl="passwordX" required placeholder="passwordX"/><br>
valid {{passwordX.valid}}
</p>
<my-form-input [placeholder]="'usernameXX'" [required]="true" [control]="usernameXX"></my-form-input><br>
valid {{usernameXX.valid}}
<p>form is valid: {{loginForm.valid}}</p>
</form>
here is only a idea of my component
@Component({
selector: 'my-form-input',
directives: [ FORM_DIRECTIVES ],
template: `
<div>
<p>
<input type="text" [attr.placeholder]="placeholder" [attr.required]="required" [attr.ngControl]="control"/><br>
valid {{control.valid}}
</p>
</div>
`
})
export class InputComponent implements OnInit {
@Input() placeholder: string;
@Input() required: boolean;
@Input() control: Control;
thx