So, I read how to create custom FormControls in Angular2, but I cannot get what I am trying to fully accomplish with validation. I have a regular input control that I want to wrap in a custom component so that I can do this:
<my-control name="something" [(ngModel)]="model.something" required></my-control>
Instead of repeating this every time:
<div class="form-group has-feedback" [ngClass]="{'has-success': someInput.valid, 'has-error': someInput.invalid && someInput.dirty}">
<label class="control-label" for="someId">{{label || 'Some Input'}}</label>
<input type="test" class="form-control" id="someId" placeholder="Some Input" [ngModel]="value" (ngModel)="onChange($event)" name="someInput" required #someInput="ngModel" minlength="8"/>
<span class="glyphicon form-control-feedback" aria-hidden="true" [ngClass]="{'glyphicon-ok': someInput.valid, 'glyphicon-remove': someInput.invalid && someInput.dirty}"></span>
<div [hidden]="someInput.valid || someInput.pristine || !someInput.errors.required" class="text-danger">Some Input is required</div>
<div [hidden]="someInput.valid || someInput.pristine || !someInput.errors.minlength" class="text-danger">Some Input must be at least 8 characters</div>
</div>
So, I implemented a custom component in the following articles on how to create custom components on the Internet:
https://blog.thoughtram.io/angular/2016/07/27/custom-form-controls-in-angular-2.html
, .. , , , , ( , - , , ). , .
, FormControl ? . , FormControl , . FormControl , . , FormControl CounterInputComponent.