I encountered an issue with the Angular Material autocomplete where it displayed a TypeError stating that it was unable to read the property 'createEmbeddedView

Using angular material autocomplete feature has been a bit challenging for me. Whenever I try to focus, I encounter the error: Cannot read property 'createEmbeddedView' of undefined

Additionally, an error pops up for every letter I input: ERROR TypeError: this.autocomplete._setVisibility is not a function. Could someone please help me understand what's going wrong with my code? I am still new to Angular.

This is the structure in my html:

<mat-form-field> 
<input formControlName="accId" matAutocomplete="auto" matInput> 
<mat-autocomplete #auto="matAutocomplete">                                                                                                                                                                                                                                                                                                                                                                                         
<mat-option *ngFor="let accId of filteredOptions">  {{accId}}  
</mat-option>                                                                                                                                                                                                                                    
</mat-autocomplete>
</mat-form-field> 

In my .ts file:

 filteredOptions: Observable<string[]>;
 ngOnInit(): void {    
    this.filteredOptions = this.form.controls['accId'].valueChanges.pipe(startWith(''),map(val => this.filter(val)));
    console.log(this.filteredOptions);
    }

  filter(val: string): string[] {
  console.log("Inside filter...");
  return this.details.listOfAccIds.filter(option =>option.toLowerCase().includes(val.toLowerCase()));
  }

Note: The structure of this.details is as follows:

Detail {listOfAccIds: Array(3), listOfCodes: Array(2), listOfReasons: Array(3)}
  listOfAccIds:(3) ["altaccId", "altaccIdss2", "altiid33"]
  listOfCodes:(2) ["code1", "code2"]
  listOfReasons:(3) ["reason1", "reason2", "reason3"]

Answer №1

Make sure to include the brackets when using the matAutocomplete directive:

<input formControlName="accId" matAutocomplete="auto" matInput>

Correct way:

<input formControlName="accId" [matAutocomplete]="auto" matInput>

Using the brackets is necessary in order to pass the reference to the variable auto. Without them, only a static string is passed which will not work since the directive requires an element reference rather than just its name.

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

Updating Facebook meta tags dynamically in Angular 4 to enhance Open Graph integration

Is there a way to dynamically update meta tags for Facebook/Whatsapp share dialog? I recently upgraded my angular 2 application to angular 4 in order to utilize the Meta service and update meta tags dynamically once data is retrieved from an API. Within ...

What could be causing the interceptor to consistently return "null" as the value when using BehaviorSubject, instead of returning the updated value?

In the process of creating an authentication application utilizing the PEAN stack (PostgreSQL - ExpressJS - Angular - NodeJS). To verify the user's sign-in status, the following steps are taken: On the backend, the session cookie is checked to deter ...

Passing variable values in Angular 6

Is there a way to transfer the value of a variable from Component1 to a variable in Component2 without using any template binding? I have two components, Header and Footer. In the Header component, there is a boolean variable called test that I need to pa ...

Having trouble launching an Angular 2 project

Something strange just happened to my Angular 2 project. Suddenly, I can't seem to start it anymore, and I'm stuck trying to figure out why based on the error messages... node_modules/@types/core-js/index.d.ts(21,14): error TS2300: Duplicate ide ...

What is the method for adding a close button to nebular tabs?

A key requirement is to display a close button after each tab has been created. Check out the code snippet that needs to be implemented: <nb-route-tabset [tabs]="tabs"></nb-route-tabset> I have thoroughly reviewed their documentati ...

Placing options and a clickable element within a collapsible navigation bar

Within my angular project, there are 4 input fields where users need to enter information, along with a button labeled Set All which will populate them. https://i.sstatic.net/1GGh1.png I am wondering how I can organize these input fields and the button i ...

Unable to simultaneously execute TypeScript and nodemon

Currently, I am in the process of developing a RESTful API using Node.js, Express, and TypeScript. To facilitate this, I have already installed all the necessary dependencies, including nodemon. In my TypeScript configuration file, I made a modification to ...

Using TypeScript with Vue in a non-component-based architecture

Recently, I've been facing a challenge while developing an application. I'm using Vue + Vuetify with typescript, but I'm trying to steer clear of creating a single-page application or using webpack to handle .vue components. My goal is to cr ...

Angular is used to call a function that captures a specific div and then waits for the capture to be completed before

I'm facing a challenge where I need to handle the capturing of a div using a method called capture() within another method. Take a look at the code snippet below: theimage; // declaring the variable callcapture() { // perform certain actions t ...

Restricting Method Arguments in TypeScript to a Specific Type

I am looking to restrict the calling party from inputting arbitrary strings as parameters to a method: // A class that provides string values (urls) class BackendUrls { static USERS_ID = (id: string) => `/users/${id}`; static CONSTANTS ...

Tips for accessing the previous route - the route that led me to the current page

Is there a way to retrieve the previous route in Angular while knowing the current route? For example, moving from tab http://localhost:4200/test/testNav/ABC to http://localhost:4200/test/SampleNav/XYZ. I need to access the previous URL (/ABC) in the ngOn ...

An issue arises in React TypeScript where a callback function is encountering undefined values when using setState, but surprisingly logs the

Struggling with a React application I'm building, specifically with an issue that's got me stumped. Here's a snippet of code that's causing trouble: onFirstNameChange(event: any){ console.log(event.target.value) // this.setState ...

Retrieve the HTML code stored as a string and showcase it within an Angular framework

I need assistance with extracting content from an email stored in a javascript/typescript string (message.body). The string contains HTML code like this: <div dir="ltr">test mail</div> Using angular bootstrap, I attempted the follow ...

Populating the DOM with a mix of strings and HTMLDivElements by iterating through an array using *ngFor

I have a specific layout requirement that needs to resemble this example: https://i.sstatic.net/4kP2q.png The desired layout should utilize CSS properties like display: grid; someFunction(data) { this.data = data; ...

Angular 2 repeatedly pushes elements into an array during ngDoCheck

I need assistance with updating my 'filelistArray' array. It is currently being populated with duplicate items whenever content is available in the 'this.uploadCopy.queue' array, which happens multiple times. However, I want to update ...

Issue NG5002: Error in Parsing: ===Symbol Not Recognized

Having trouble in Angular with a micro-frontend project. When running the angular 16 project, we encountered the following error: Error NG5002: Parser Error - Unexpected token === https://i.sstatic.net/LwivL.png ...

Adding an object with a composite key to an IndexedDB object store is not permitted as the key already exists within the store. This limitation occurs when attempting to add an entry

I am facing an issue with my objectStore where adding an object with the same productId but a different shopName triggers an error in the transaction showing: ConstraintError: Key already exists in the object store.. This is how I initialized the objectSto ...

The subdirectory './src/ngtsc/reflection' is not included in the "exports" section of the '/node_modules/@angular/compiler-cli/package.json' file

Having an issue while attempting to run ng test using jest and encountering the following error message: Package subpath './src/ngtsc/reflection' is not defined by "exports" in /Users/oyf992/source/app-mngt/node_modules/@angular/compiler-cli/pac ...

Triggering event within the componentDidUpdate lifecycle method

Here is the code snippet that I am working with: handleValidate = (value: string, e: React.ChangeEvent<HTMLTextAreaElement>) => { const { onValueChange } = this.props; const errorMessage = this.validateJsonSchema(value); if (errorMessage == null ...

Unable to iterate over a 2D array using 'rows' in JavaScript or TypeScript

Imagine I need to generate a 2D array with this specific structure: [0, 1, 1, 1] [1, 0, 0, 0] [1, 0, 0, 0] To achieve this, I first initialized a 2D array with 0 values: function createGrid(m: number, n: number): number { let grid: number[][] = new Ar ...