I'm working on a project in which a search feature has been implemented. The input element looks like this :
<input #input type="text" name="query" class="form-control" id="nav-input" (ngModelChange)="onquery($event)"
[(ngModel)]="searchdata.query" autocomplete="off" (keypress)="onEnter($event)">
onEnter(event: any) {
if (event.which === 13) {
this.displayStatus = 'hidebox';
event.target.blur();
this.submit();
}
submit() {
if (this.searchdata.query.toString().length !== 0) {
if (!this.router.url.toString().includes('/search')) {
this.router.navigate(['/search'], {queryParams: this.searchdata});
}
On typing a query and hitting enter key, it shows error in console:
Form submission canceled because the form is not connected
I'm not able to figure out, how to solve this issue. It will be great if someone can help me out. :)
enteryou are triggering the form submit. Have you checked that?submitmethod<form>not just the<input><form>element, just<input>element inside div tag.formelement. Justinputinside div tag. Andsubmit()is with whole code. :)