Potential uncertainty in Angular FormControl email validation due to potential null Object

Whenever I run the command ng s --aot, I encounter this message: Object is possibly 'null'.

I've been trying various solutions all morning to resolve it, but without success. The issue seems to be related to objects like email.valid, dirty, etc. within the code snippet below:

<form class="form-inline md-form form-sm" [formGroup]="validatingForm" (submit)="update(emailInput.value)">
          <input mdbInput mdbValidate type="email" class="form-control form-control-sm mr-3 w-75" placeholder="Enter user's email" aria-label="Search" formControlName="email" #emailInput required />
          <button mdbBtn type="button" color="primary" mdbWavesEffect (click)="update(emailInput.value)">
            <mdb-icon fas icon="search" aria-hidden="true"></mdb-icon>
          </button>
          <mdb-error *ngIf="email.invalid && (email.dirty || email.touched)" class="mt-2">Email invalid</mdb-error>
          <mdb-success *ngIf="email.valid && (email.dirty || email.touched)" class="mt-2">Email valid</mdb-success>
        </form>

The TypeScript code snippet associated with this is as follows:

 export class UsersComponent implements OnInit {
      validatingForm: FormGroup;
      token: any;
      userDetails: {};
      hasUsers = false;
      emailValue: string;
      constructor(private crudService: CrudService) {}

      ngOnInit() {
        this.validatingForm = new FormGroup({
          email: new FormControl("", Validators.email)
        });
        this.loginAsAdmin();
      }

      get email() {
        return this.validatingForm.get("email");
      }

Answer ā„–1

*ngIf="email && email.valid && (email.dirty || email.touched)" @ritaj

Answer ā„–2

Simply adding a conditional directive *ngIf="email" can rectify the issue.

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

Transform an angular1 javascript circular queue implementation for calculating rolling averages into typescript

I am currently in the process of migrating a project from Angular 1 to Angular 2. One of the key components is a chart that displays a moving average line, which requires the use of a circular queue with prototype methods like add, remove, and getAverage. ...

Unsynchronized state of affairs in the context of Angular navigation

Within my Angular project, I am currently relying on an asynchronous function called foo(): Promise<boolean>. Depending on the result of this function, I need to decide whether to display component Foo or Bar. Considering my specific need, what woul ...

Leveraging AWS SSM in a serverless.ts file with AWS Lambda: A guide to implementation

Having trouble utilizing SSM in the serverless.ts file and encountering issues. const serverlessConfiguration: AWS = { service: "data-lineage", frameworkVersion: "2", custom: { webpack: { webpackConfig: "./webpack ...

Securely connecting Angular front end with NodeJS backend server using HTTPS encryption

I am currently using a frontend built with Angular 7 and ngx-admin, along with a backend developed in nodeJS and Express. The issue: The Angular frontend uses HTTPS to communicate with the backend via HTTP. This has caused the following problem: Mixed Co ...

Merge mocha with Typescript, and include the watch feature

For my project, I have set up mocha to test my Typescript code. The issue arises when running the command: mocha ts/test --compilers ts:typescript-require Every time I make a change, it fails with an error message like this: error TS2307: Cannot find mo ...

Utilizing props in styled-components: A beginner's guide

I am trying to pass a URL to a component so that I can use it as the background image of the component. Additionally, I need to check if the URL is empty. Component: <BannerImg/> CSS (styled): `const BannerImg = styled.img` background-image: url( ...

Exploring Angular 2 with ng-bootstrap Library

As I delve into learning Angular2, my goal is to incorporate ng-bootstrap into my project. However, I have encountered issues when trying to import ng-bootstrap and create a functional project. Being a novice in this field, I am unsure if the problem lies ...

What is the best way to transfer information within the same webpage?

https://i.sstatic.net/umfln.pnghttps://i.sstatic.net/9W6ZE.pngI'm just starting out with angular 2/4 projects and I have a popup search tab in the interface that displays an editable list. However, I am unsure about how to transfer data to the main i ...

Exploring the Best Approach to Test RxJS Subject with Jasmine in Angular

I am very new to writing Jasmine unit test cases and I have a scenario that may be simple, but I am unsure of how to cover the test case for ngInit in the following class. Can anyone provide assistance? export class Component1 implements OnInit { deta ...

I am in need of a customized 'container' template that will display MyComponent based on a specific condition known as 'externalCondition'. MyComponent includes the usage of a Form and formValidation functionalities

container.html <div ngIf="externalCondition"> <!--Initially this is false. Later became true --!> <my-component #MyComponentElem > </my-component> <button [disabled]= "!myComponentElemRef.myDetailsF ...

The process of releasing a component created with angular-starter onto npm is now underway

After creating angular components with the Angular Starter Kit from https://github.com/AngularClass/angular-starter, I am looking to package them and deploy them on NPM for easy use in other projects. However, I found the documentation to be lacking in thi ...

Angular button not functioning properly with disabled attribute

I have been experimenting with both [disabled] or disabled but it doesn't seem to be working according to my TypeScript conditions. There are 4 buttons that I need to disable based on various TypeScript conditions. I have a total of 7 conditions that ...

Ported an Angular application to Android with the help of Cordova. The APK successfully launches on the emulator, however, when tested on a physical device, only a blank

Struggling to convert my angular app with Cordova to an android app. The APK file works on the emulator, but when installed on a real device, it only shows a white blank screen, never loading. Seeking assistance as I am new to Cordova and Android developme ...

Is it no longer possible to instantiate an object using the syntax <interface>{}?

There seems to be an issue with the code snippet below when run in the TypeScript playground: interface Person { name: string; age: number; } const makePerson= function(name : string, age : number) : Person { let obj = <Person>{} ...

I am unable to utilize ts-node-dev for launching a TypeScript + Express + Node project

When I try to execute the command npm run dev, I am unable to access "http://localhost:3000" in my Chrome browser. Task Execution: > npm run dev <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fe90919a9bd3988c9f939b89918c9 ...

Unable to apply styling to table cells that are dynamically added using JQuery within an Angular

Currently working on setting up a form using Angular. Within the hotel.view.html file, there is a table that looks like this: <table id="rooms"> <tr> <td>Room Type</td><td>Beds</td><td>Q.ty</td ...

Ways to implement pointer event styling within a span element

Hi, I'm having trouble with styling and I can't seem to figure out how to resolve it. The style pointer-events: none doesn't seem to be working for me. Here is an example of my code: The style snippet: .noclick { cursor: default; ...

Storing multiple strings in a string array in Angular2

Hi everyone, Iā€™m just getting started with Angular and currently working on creating a recipe page that fetches data from an API. The API setup is complete, but now I need to figure out how to input the data into the API using Angular. I have defined a ...

Tips for avoiding parent div click interference in Angular

Working with Angular8, I have a div containing a routelink along with other components including a checkbox. Here's the structure: <div [routerLink]="['/somewhere', blablabla]"> <!--other components that navigate to the ro ...

Issue with TypeScript retrieving value from an array

Within my component.ts class, I have defined an interface called Country: export interface Country{ id: String; name: String; checked: false; } const country: Country[] = [ { id: 'India', name: 'India', checked: false}, { ...