Angular App hides the Material Form Controls

Recently, I delved into learning Angular 6 and decided to test my knowledge by creating a simple form. However, I encountered an issue: the form controls are not visible at first glance, but when clicked on the right spot, they appear.

Below are screenshots depicting the situation:

Main Screen :

https://i.sstatic.net/6epA0.png

Elements on click :

https://i.sstatic.net/RawoL.png

https://i.sstatic.net/dqYbD.png

The code structure is quite basic; I have a component called FormTestComponent and a Module (MaterialModule) that includes all the necessary Material modules. Surprisingly, there are no errors showing up in the console.

You can access all the files from this git repository:

https://github.com/Shyrro/NewTry/tree/master/ClientApp/src/app

I am left wondering if I overlooked something crucial?

Answer №1

To include the theme in your project, simply add the following line to your style.scss file:

@import "~@angular/material/prebuilt-themes/indigo-pink.css";

While the theme works well on its own, you can enhance it further by adding the following modules:

Add FormsModule and ReactiveFormsModule to your AppModule:

import { FormsModule, ReactiveFormsModule } from '@angular/forms';

@NgModule({
  ...
  imports: [
    FormsModule,
    ReactiveFormsModule
  ],
  ...
})
export class AppModule { }

HTML:

<form [formGroup]="basicForm" class="example-form">
  <mat-form-field>
    <input matInput formControlName="test" placeholder="Just a test">
  </mat-form-field>
  <mat-form-field>
    <mat-select formControlName="select" placeholder="Select">
      <mat-option value="option">Option</mat-option>
    </mat-select>
  </mat-form-field>
</form>

TS:

import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder } from '@angular/forms';

@Component({
  selector: 'app-form-test',
  templateUrl: './form-test.component.html',
  styleUrls: ['./form-test.component.scss']
})
export class FormTestComponent implements OnInit {
  basicForm: FormGroup;

  constructor(private fb: FormBuilder) {}

  createForm() {
    this.basicForm = this.fb.group({
      test: '',
      select: ''
    });
  }

  ngOnInit() {
    this.createForm();
  }
}

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

Looking for a way to dynamically append a child element within another child

Struggling to include a new child within a specific child in Json myObject:any[] = []; this.myObject = { "type": "object", "properties": { "first_name": { "type": "string" }, "last_name": { "type": "string" }, } } addF ...

A TypeScript function that converts a value into an array if it is not already an array, ensuring the correct type is output

I'm attempting to develop a function that wraps a value in an array if it is not already an array. export function asArray<T extends Array<any>>(value: T): T export function asArray<T>(value: T): T[] export function asArray(value: a ...

Step-by-step guide for sending information to a personalized API using Ajax on the Syncfusion Angular Scheduler

I'm currently grappling with how to send data to my API whenever a new event is created using the editor window. My approach so far involves using Ajax to fetch content, as seen in the code snippet below; const ajax: Ajax = new Ajax( "https://l ...

Issue with Angular / SCSS where animation is not being executed on the specified element

I have created a post component with a comment section. However, when I click on the comments, I want them to display smoothly with a nice animation effect. Even though I have added the necessary code for animations, it doesn't seem to work as expecte ...

Solidjs: Implementing a Map in createStore does not trigger updates upon changes

As a beginner in solidjs, I might have missed something important. In the code snippet below, I am trying to understand an issue: const [state, setState] = createStore({ items: new Map() }); // e.g. Map<number, string> In a component, suppose I want ...

How to delete all markers on a Google map in Angular 6

<div #gmap class="map"></div> for (let marker of this.markersDisplay) { let markerColor = (marker.MarkerType == MarkerType.Ok) ? "green" : (marker.MarkerType == MarkerType.Warning) ? "yellow" : "red"; let markerClick = new ...

Secure Your Angular Application on Heroku with Best Security Practices

I am encountering an issue with my Angular application routing: const routes: Routes = [ { path: '', component: HomePageComponent }, { path: 'rome-routing', component: SomeRoutingComponent}, { path: 'other-routing', comp ...

The template fails to reflect the changes in Signal's value

Here is the structure of my code: {{ announcements().start | date: "d MMM" }} - {{ announcements().end | date: "mediumDate" }} <button type="button" class="btn btn-primary" (click)="goForward()"> & ...

Return a potential undefined output

I am working with a variable called root which could potentially be undefined. Its value is only determined at runtime. const root = resolvedRoot || await this.fileSystem.getCurrentUserHome(); console.log('root.uri = ' + root.uri); The existenc ...

Is it possible that React.createElement does not accept objects as valid react children?

I am working on a simple text component: import * as React from 'react' interface IProps { level: 't1' | 't2' | 't3', size: 's' | 'm' | 'l' | 'xl' | 'xxl', sub ...

Updating our project from Angular version 17 to version 18

Seeking guidance on updating a project from Angular v17 to v18 as there seems to be a lack of documentation on version updates available on the official angular.dev website. Any assistance or guidance on this matter would be greatly appreciated. Thank yo ...

What distinguishes between the methods of detecting falsy and truthy values?

While working with JavaScript / Typescript, I often find myself needing to verify if a length exists or if a value is true or false. So, the main query arises: are there any differences in performance or behavior when checking like this... const data = [ ...

The console is displaying 'undefined' when attempting to render the JSON response in Vue

In my vue.js application, I'm trying to display text using TypeScript. Here is an example of the JSON response: { "data": [ { "firstName": "Foo", "lastName": "Smith" }, { "firstName": "Mi ...

What could be causing the excessive number of connections in my MongoDB instance?

This code snippet is crucial for my initial connection setup let cachedDbConnection: Db export async function establishDatabaseConnection(): Promise<{ db: Db }> { if (cachedDbConnection) { return { db: cachedDbConnection } } const client ...

Is it possible to minimize the number of accessors needed for reactive forms?

Currently, I am dealing with a reactive form that consists of 20 different inputs. An example of one input is shown below: <input formControlName="name" matInput> For each input, I find myself needing to write an accessor function like the ...

What is the most recent stable version of Angular recommended for utilizing ui-bootstrap?

I've been working on updating an older angular application and I'm interested in incorporating ui bootstrap for more advanced features. However, the current version of Angular used is 1.2.18 and any attempt to upgrade it to a higher version resul ...

Creating a customizable filter by using the function of an object

I am currently developing a customizable dynamic filter system, similar to the functionalities offered by Yahoo Screener. To achieve this, I have defined an interface for the available filter fields: export interface FilterField { label: string; se ...

Configuring the parameters property for a SSM Association in AWS CDK

I am working on utilizing the AWS Systems Manager State Manager to automate shutting down an RDS instance at 9PM using a cron job. Currently, I am constructing the CloudFormation template with the help of AWS CDK. While going through the AWS CDK documenta ...

What is the relationship between directives, templates, and ViewContainers in Angular?

I have implemented a basic functionality in my component where numbers are injected after a delay using a custom directive called *appDelay It is known that the Angular syntax hints with * will de-sugar into something like this: <ng-template ...> .. ...

Navigate through collections of objects containing sub-collections of more objects

The backend is sending an object that contains an array of objects, which in turn contain more arrays of objects, creating a tree structure. I need a way to navigate between these objects by following the array and then back again. What would be the most ...