Transmitting FormControl to External FormBuilder in Angular 8

I am currently working on creating a wrapper for Angular Material Select. I am trying to find out how to transfer the FormControl from the Inner Component (Material dropdown select) to an external Parent Component Formbuilder. I am exploring different syntaxes and hoping to avoid using ControlValueAccessor if possible.

Child Material Dropdown Select:

TS:

@Input() formControlInput = new FormControl('',[Validators.min(1)]])

HTML:

<div class="dropdown-cont">
    <mat-form-field appearance="outline">
        <mat-label>{{label}}</mat-label>
        <mat-select
            [formControl]="formControlInput"  // This is where it needs to go
            [(ngModel)]="selectedItem"
            (selectionChange)="selectedItemChanged($event)"
            >
            <mat-option [value]="defaultItem[txtValue]">{{defaultItem[txtField]}}</mat-option>
            <mat-option
                *ngFor="let item of listItems"
                [value]="item[txtValue]"
            >
            {{item[txtField]}}
            </mat-option>
        </mat-select>
    </mat-form-field>
</div>

Parent Component:

this.outerForm = this.formBuilder.group({
'customerName':[null,[Validators.maxLength(50)]],
'customerPhone': [null, [Validators.maxLength(15)]],
'formControlInput': [null,[Validators.required]], // <--- Need this from inner component

How can I pass the FormControl from the child Material dropdown select in the inner component to the external formBuilder in the parent component?

Answer №1

To send data from a child component to a parent component in Angular, you can utilize the @Output() decorator along with an EventEmitter. Simply call the emit(formControl) method within the ngOnInit() lifecycle hook of the child component.

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

Encountered an error during npm installation: Fetch Package Metadata error occurred while attempting to request from http://registry.npmjs.org/concurrently, the cause being a socket hangup

I am encountering the following errors: "An unexpected fetchPackageMetaData error occurred while making a request to http://registry.npmjs.org/concurrently failed due to a socket hang up." I am currently connected through a corporate proxy with the firew ...

Setting up Node on a Ubuntu system

Currently, I am in the process of installing Node.js to run my Angular2 program. However, I encountered an error during the installation: npm WARN npm npm does not support Node.js v0.10.25 npm WARN npm You should probably upgrade to a newer version of nod ...

Surveying in TypeScript-React

I am currently working on incorporating a polling feature in React using TypeScript. This polling function is required to make a REST API call to retrieve a record from DynamoDB and then continue polling every 30 seconds until the 'Status' field ...

The 'XX' Typescript type does not match the type import ("/Volumes/D/test").XX.ts(2322)

I wrote a piece of code to customize the default configuration for a Class, but I encountered an unusual error message: Type 'IConfig' is not assignable to type 'import("/Volumes/D/www/js/tsc_1/test").IConfig'.ts(2322) It seems that I ...

Learning how to effectively incorporate two matSuffix mat-icons into an input field

I'm currently experiencing an issue where I need to add a cancel icon in the same line as the input field. The cancel icon should only be visible after some input has been entered. image description here Here's the code I've been working on ...

Addressing the issue of potential null objects within an Angular FormGroup

While working on my Angular-15 project, I encountered an issue with the code in the component.ts file: component.ts: export class CountryCreateComponent { countriesData: any[] = []; selectedCountryCode: string = ''; selectedCountr ...

Setting up Mailgun with TypeScript on Firebase Cloud Functions

Currently, I am working on a Cloud Function within Firebase to integrate with Mailgun for sending emails, following the guidelines provided in the Mailgun documentation. My challenge lies in implementing this functionality using TypeScript, as I have been ...

Learn how to dynamically activate an icon in Angular to enhance user interaction

HTML Code: The Zoom Component <div class="zoom py-3"> <i nz-icon nzType="minus" (click)="zoomToggle(false)" nzTheme="outline"></i><br> <i nz-icon nzType="plus" (click)=&q ...

Check at least one checkbox in Ionic 3

My Ionic 3 form consists of 3 checkboxes fields: <form [formGroup]="bookingForm" (ngSubmit)="addBooking()"> <ion-card> <ion-card-content> <ion-item-group formGroupName="period"> <ion-list> <ion-list-hea ...

Ways to retrieve dictionary keys as an array in Angular

Here is an example of an Angular dictionary: { ARRAY1: [{...}, {...}, {...}] ARRAY2: [{...}, {...}, {...}] ARRAY3: [{...}, {...}] ARRAY4: [{...}] } I want to show all the keys of arrays from this dictionary on an HTML page. I attempted to do ...

The TS2345 error is triggered when using the fs.readFile function with specified string and

Attempting to utilize the fs.readFile method in TypeScript, my code looks like this... import {readFile} from 'fs'; let str = await readFile('my.file', 'utf8'); This results in the following error message: TS2345: Argumen ...

Are you interested in verifying the user's login status on the website using a Chrome extension?

My latest project involves creating a chrome extension using angular for a PHP website. Currently, the extension is working smoothly. It features a button that I would like to have the ability to enable or disable based on whether the user is logged in o ...

The variable isJoi has been set to true but there is an error due to an unexpected

I am currently developing a NestJs backend on multiple machines. One of the machines is experiencing issues with the @hapi/joi package. When running the NestJs application in development mode on this specific machine, I encounter the following error: PS C ...

Implement conditional props for a React component by linking them to existing props

In my current project, I am working on a component that has a loading state. The component has an isLoading prop which determines whether the component is currently in a loading state or not: interface CustomImageComponentProps { isLoading: boolean ...

CORS restrictions causing issues with Angular app on NGINX server

My server (Angular served by NGINX) has a specific request to find the closest schools, hospital, and transport based on longitude and latitude coordinates. However, when I try to execute the request, I encounter a CORS header error on the server. The err ...

Error in TypeScript: The type 'Color' cannot be assigned to the type '"default" | "primary" | "secondary"'

Currently, I am utilizing MUI along with typescript and encountering the following issue. It seems like I may be overlooking a fundamental concept here but unfortunately cannot pinpoint it. Error: Type 'Color' is not assignable to type '&quo ...

Enhancing supertest functionality with Typescript

Currently, I am working on extending the functionality of supertest. After referencing a solution from Extending SuperTest, I was able to implement the following example using javascript: const request = require('supertest'); const Test = reque ...

What is the best approach for designing a UI in Angular to showcase a matrix of m by n dimensions, and how should the JSON format

click here for a sneak peek of the image Imagine a matrix with dimensions m by n, containing names on both the left and top sides. Remember, each column and row must be labeled accordingly. ...

Nest JS - The client validation has not passed: The path field is mandatory

I'm seeking help here because I've hit a roadblock with an issue I've been facing for the past few hours. I'm working on building an API using Nest JS 8 and MongoDB, which I test using Postman. When I try to send a POST request (http:// ...

Issues with Angular's router outlet link functionality not performing as expected

I am encountering difficulties trying to create a link to a named router outlet in Angular. Let's focus on the most crucial part of the code: app-routing-module.ts: import { NgModule } from '@angular/core'; import { RouterModule, Routes } ...