Experiencing a Challenge with Angular Form Validation

Can anyone assist me in figuring out why I keep encountering this issue of falling?

An 'name' does not exist in type 'ValidatorFn | ValidatorFn[] | AbstractControlOptions', as object literals may only specify known properties.

export class AddContactFormComponent implements OnInit {
  public isShowForm:boolean = false;
  
  public addContactForm: FormGroup;

  public showFrom(): void{
    this.isShowForm = true;
  }
  ngOnInit(): void {
    this.addContactForm = new FormGroup(controls: {
      name: new FormControl(null,{validators:[Validators.required]}),
      phone: new FormControl(null,{validators:[Validators.required]}),
    })
  }

}
<button class="add-contact" *ngIf="!isShowForm" (click)="showFrom()">Add new contact</button>

<form action="" *ngIf="isShowForm" [formGroup]="addContactForm">
  <div class="form__body">
    <div class="form__group">
      <label for="">Name</label>
      <input type="text" placeholder="name" formContralName="name">
    </div>
    <div class="form__group">
      <label for="">Phone</label>
      <input type="text" placeholder="Phone" formContralName="phone">
    </div>
  </div>
  <div class="form__footer">
    <button type="sumbit" class="submit">create contact</button>
  </div>
</form>

Answer №1

Angular's formBuilder is a valuable tool for creating forms.

For instance:

this.contactForm = this.formBuilder.group({
  name: ['', Validators.required],
  email: ['', Validators.email]
});

Remember to include the formBuilder in your constructor.

You can still manually create the form, but there might be a syntax error in your code.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilize Office Scripts to update values across numerous worksheets

Looking for ways to improve the performance of this script, as it currently takes 45 seconds to run. Any ideas? function main(workbook: ExcelScript.Workbook) { try { const sheets = workbook.getWorksheets(); for (let sheet of sheets) { const break ...

Obtain a hidden item using *ngIf in Angular for testing purposes

Snippet of HTML Code: <div *ngIf="state"> <p>some text<p> <button (click)="increment()" class="myButton">Increment</button> </div> My Component Structure: @Component( ...

Using Angular 2 for two-way binding with input masking

Encountering an issue with ng2 and inputmask. Here is the code snippet that's causing trouble: <div class="form-group col-sm-7"> <label class="control-label" for="sender-phone">Phone *</label> <input type="text" [(ngModel) ...

The npm installation process is displaying unlinked versions of Angular components

I have recently updated a shared library in my Angular application, utilizing a local shared component via our custom npm server, Verdaccio. After updating the library and using npm link to share it within my application for testing, everything went smoot ...

Creating a unique theme export from a custom UI library with Material-UI

Currently, I am in the process of developing a unique UI library at my workplace which utilizes Material-UI. This UI library features a custom theme where I have integrated custom company colors into the palette object. While these custom colors work perfe ...

Trigger a function upon clicking a button within a Material-UI component

Just set up my MUI static date picker and here's how it looks: https://i.sstatic.net/4Yk7m.png Any tips on how to detect arrow clicks so I can trigger a function? I have a calendar next to this component and want it to display the corresponding mont ...

The Flexbox card is struggling to occupy the available space

This image should clarify things https://i.sstatic.net/x8rL5.png How can I make those cards fill the remaining space properly? I've tried a few things but nothing seems to work... <div class="card"> <div class="card-heade ...

Struggling to configure Sass with @snowpack/app-template-react-typescript

I'm struggling to integrate Sass with the @snowpack/app-template-react-typescript template. I attempted to follow the steps outlined in this guide, but so far I haven't been successful. I even created a new project and tried adding it, but not ...

Importing components in real-time to generate static sites

My website has a dynamic page structure with each page having its unique content using various components. During the build process, I am statically pre-rendering the pages using Next.js' static site generation. To manage component population, I have ...

How can you switch alignment from left to right when the current alignment settings are not functioning as expected in HTML?

I need the buttons +, count, and - to be right-aligned on my page. The numbers on the right are taking up the same amount of space, while the names on the left vary in length. I want the buttons to always remain in the same position, regardless of the name ...

What is the best way to save a Map for future use in different components?

Let's say I define an enum like this: export enum SomeEnum { SomeLongName = 1, AnotherName = 2 } Within my display components, I'm utilizing an enum map to translate the enum values into strings for presentation on the web app: enumMap = new Map ...

Error message: In Angular 8 using Jest instead of Jasmine, there is no exported member called 'SpyObj'

I recently made a switch in my Angular CLI project from Karma to Jest by following this helpful tutorial. However, after the transition, I've noticed that some tests are passing while others are failing. One issue I encountered involves declaring a v ...

Restricting types through property union types

I'm currently in the process of refining a type to a specific variant within a type, but I am encountering difficulties in accurately defining the correct type. At this moment, my type Item has the potential for having various types for its details. t ...

Issue with checkbox click event binding in Angular 6 not functioning as expected

I am currently utilizing a reactive form to display a list of heroes to the user and would like to trigger a console log message when the user selects a hero by clicking on a checkbox. The issue I am encountering is that when I print this.form in the cons ...

Tips for choosing the correct type of object to use for styling in Vue/Typescript: { }

This is how I implement styling in my Vue TypeScript project. private styleTableObject: CSSStyleSheet = { width: '100%', height: '76%' } I am being forced to use the any type. private styleTableObject: any = { ...

An easy way to nest a child component within a parent component in Angular 2 is

I'm a beginner in angular2 and I'm having trouble registering a child component in a parent component. ParentComponent: AppComponent is the parent component HeaderComponent is the child component The Angular documentation suggests using direc ...

When altering the value format, the input shows NaN

Inside a mat form field, I have an input: <mat-form-field style="padding-right: 10px;"> <input matInput type="text" [ngModel]="value | formatSize" (ngModelChange)="value=+$event"; placeholder="value" [ngModelOptions]="{standalone: true}"&g ...

How can I retrieve the page size of Syncfusion.Grid within an Angular application?

I am integrating Syncfusion into my Angular project. Whenever a paging event occurs, I need to retrieve the current page and page size of the grid. Below are the relevant code snippets: component.html: <ejs-grid #Grid class="data-grid" (recor ...

Using React's `cloneElement` to make modifications to a child component while maintaining the reference within a functional component

In the past, I had references in my component while rendering, and it was functioning as expected: // props.children is ReactElement<HTMLDivElement>[] const [childRefs] = useState<RefObject<any>[]>(props.children.map(() => createRef()) ...

Ways to conceal all rows in Ag-grid during data loading

Currently, I am utilizing "ag-grid-angular": "^25.3.0" along with "ag-grid-community": "^25.3.0" As I fetch data from the server, I encounter an issue where an empty row briefly appears right before the grid is rend ...