formControl or formControlName
([(ngModel)]
(value/checked properties and change/input/blur event
listenersControlValueAccessor interface for seamless two-way data binding with your
model.FormControl and bind it directly with [formControl], or use a FormGroup and bind individual controls by name
with formControlName. See the <p-input-text [formControl]="myInputText" [label]="'Some Label'" />
...
myInputText = new FormControl('');
<p-input-text formControlName="myInputText" [label]="'Some Label'" />
...
form = new FormGroup({
myInputText: new FormControl(''),
});
[(ngModel)], or
withing a form by linking them with their name using the ngModel directive. For more details, see the
<p-input-text [(ngModel)]="myInputText" #ctrl="ngModel" [label]="'Some Label'" />
...
myInputText: string = '';
<form #f="ngForm" (ngSubmit)="onSubmit(f)" novalidate>
<p-input-text :name="'myInputText'" ngModel [label]="'Some Label'" />
</form>
...
onSubmit(f: NgForm) {
console.log(f.value);
}
value or checked props along with input, change, and blur events. This approach allows flexible
integration with any form library.<p-input-text [value]="value" (input)="onInput($event)" :name="'myInputText'" :label="'Some Label'" />
...
value: string = '';
onInput(e: CustomEvent<InputTextInputEventDetail>) {
this.value = (e.detail.target as HTMLInputElement).value;
}
<form (ngSubmit)="onSubmit(f)">
<p-input-text :name="'myInputText'" :label="'Some Label'" />
</form>
...
const onSubmit = (form: NgForm) => { console.log(form.value); };
