1
I’m making a small app, which takes a message typed in the form and records it on the console. I tried to import several items and found similar problems to mine on the internet but they did not help me. I am getting this error:
Can’t bind to 'formGroup' Since it isn’t a known Property of 'form'.
app.component.html:
<div class="content" role="main">
<a>
<form [formGroup]="pushForm"> <!--Show the error here -->
<label>Titulo:</label>
<input class="form-control" formControlName="titulo">
<label>Menssagem:</label>
<input class="form-control" formControlName="menssagem">
<button (click)="printConsole();" >Enviar Menssagem</button>
</form>
</a>
</div>
<router-outlet></router-outlet>
app.componentts.:
import { Component, NgModule } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { FormControl, FormGroup } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
@NgModule({
imports: [
BrowserModule,
ReactiveFormsModule
],
})
export class AppComponent {
pushForm = new FormGroup ({
titulo: new FormControl(),
mensagem: new FormControl(),
});
printConsole() {
console.log("Menssagem: "+ this.pushForm.value);
}
}
There is nothing wrong, at least in the Angular part, it may be that the problem is a tag
<form>
within a tag<a>
, other than that there is no problem in the code!– LeAndrade
I took the <a> tag, but it’s still a problem. ):
– Kaya Ryuuna
Strange, because apparently you imported and declared everything correctly, I just think you should (which is standard in development with Angular) separate the module in one file and the class in another, everything in one file only gets bad to keep as the application grows, gets messy. Now as for the problem I can’t see the pq of the error sincerely.
– LeAndrade