I'm trying to create a custom component with an input form control inside but I have no idea how to connect the directive formControl and formControlName to the inner input, this is my code:
<div class="input-group">
<input class="form-control form-control-sm"
#code />
<div class="input-group-append">
<button type="button" class="btn btn-sm btn-success"
(click)="search()">
<i class="fa fa-search"></i>
</button>
</div>
</div>
this is the .ts file
import { Input, Component, forwardRef, OnInit, ViewChild } from '@angular/core';
import { DefaultValueAccessor, ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'search-input',
templateUrl: './search-input.component.html',
styleUrls: ['./search-input.component.scss'],
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => SearchInputComponent),
multi: true
}
]
})
export class SearchInputComponent implements OnInit, ControlValueAccessor {
writeValue(obj: any) {
}
registerOnChange(fn: any) {
//this.valueAccesor.registerOnChange(fn);
}
registerOnTouched(fn: any) {
//this.valueAccesor.registerOnTouched(fn);
}
setDisabledState(isDisabled: boolean) {
//this.valueAccesor.setDisabledState(isDisabled);
}
}
It should
<search-input formControlName="code">
Or
<search-input formControl="code">
Please, help me with this, I don't have much experience with Angular