`mat chip component in Angular Material is malfunctioning`

Whenever I input a string, it does not display properly within the designated textbox.

HTML

      <mat-form-field class="favorite-fruits">
        <mat-label>Favorite Fruits</mat-label>
        <mat-chip-list #chipList aria-label="Fruit selection">
          <mat-chip *ngFor="let fruit of fruits" (removed)="remove(fruit)">
            {{fruit.name}}
            <button matChipRemove>
              <mat-icon>cancel</mat-icon>
            </button>
          </mat-chip>
          <input placeholder="New fruit..."
                 [matChipInputFor]="chipList"
                 (matChipInputTokenEnd)="add($event)">
        </mat-chip-list>
      </mat-form-field>

ts

import { COMMA, ENTER } from '@angular/cdk/keycodes';
import { MatChipInputEvent } from '@angular/material/chips';

export interface Fruit {
  name: string;
}

@Component({
  selector: 'my-story',
  templateUrl: './my-story.component.html',
  styleUrls: ['./my-story.component.scss']
})
export class MyStoryComponent implements OnInit {
      fruits: Fruit[] = [];
    
      add(event: MatChipInputEvent): void {
        const value = (event.value || '').trim();
    
        // Add our fruit
        if (value) {
          this.fruits.push({name: value});
        }
      }
    
      remove(fruit: Fruit): void {
        const index = this.fruits.indexOf(fruit);
    
        if (index >= 0) {
          this.fruits.splice(index, 1);
        }
      }
}

css

.favorite-fruits {
    width: 100%;
}

https://i.stack.imgur.com/qQ3NU.png

This is the link I referenced: https://material.angular.io/components/chips/overview

Thank you for your assistance.

Answer №1

It seems like you're currently using a version of Angular that is below v12 and reviewing the documentation for v12 or higher.

If you are working with Angular v12 or lower, use the following code:

<mat-icon matChipRemove>cancel</mat-icon>

For Angular v12 and above, use this updated code:

<button matChipRemove>
    <mat-icon>cancel</mat-icon>
</button>

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

When attempting to utilize expo-av in a React-Native project on iOS, the recorded MP4 file encountered an issue when trying to submit it as form data for Open

I've been working tirelessly through the night, trying to record myself on my iPhone using expo-av to capture speech and then upload it to openai's transcriptions endpoint with the whisper-1 model. The recording is saved as an mp4 file, which I ...

Leverage Custom_Pipe within TS

I am currently working with a pipe that I have created. Here is the code: @Pipe({ name: 'searchNomES' }) export class SearchNomESPipe implements PipeTransform { transform(uos: IUo[], name?: string,): IUo[] { if (!uos) return []; if (!name) ret ...

The argument representing 'typeof Store' cannot be assigned to the parameter representing 'Store<AppState>'

I'm encountering an issue while trying to expand a service in Angular that utilizes ngrx. The error message I'm receiving is as follows: Argument of type 'typeof Store' is not assignable to parameter of type 'Store<AppState>& ...

Initial state was not properly set for the reducer in TypeScript

Encountered an error while setting up the reuder: /Users/Lxinyang/Desktop/angular/breakdown/ui/app/src/reducers/filters.spec.ts (12,9): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ selectionState: { source: ...

Troubleshooting Problem with Angular Material 2's Mat-Paginator [Length] Bug

Utilizing the mat-paginator component for a table, I am facing an issue where I am unable to dynamically set the length of the paginator based on the total number of results retrieved from an API call. Despite trying various methods like setting it in the ...

Employ the VSTS node API to retrieve all commits within a specified branch

I have been utilizing the vsts-node-api with reasonable success. However, my goal is to retrieve all commits in a specific branch, as detailed in the REST API documentation located here. Unfortunately, the node api only allows for commit queries in a rep ...

In Rxjs, Subscribe now emits individual items one at a time instead of emitting a list all at once

I've encountered an issue in my Angular 4 application while working with Rxjs and I can't seem to figure out the behavior. Here's a snippet of my code: this.server.get("incidents") //http get resource .flatMap((res) => res.value) //the ...

Loading a Dynamic URL within a Component's template in Angular 2.0.0-rc.1

Is there a method for dynamically loading URLs in the templateUrl property? Similar to the code snippet below: @Component({ moduleId: module.id, selector: 'my-app', templateUrl: DynamicUrl, // Load DynamicUrl here styleUrls: [&ap ...

Get rid of the filter arrows in the top row of a styled SpreadJS spreadsheet

Exploring SpreadJS for the first time has been an interesting journey as I dive into understanding table styling. While trying to apply styles across the entire table, I noticed a peculiar issue that arises. Upon applying a theme, whether it be custom or ...

When attempting to utilize class validators in NestJS, Param is refusing to cast to DTO type

I'm currently working on implementing validation for the parameter I receive in a request, especially when trying to delete something. The parameter is expected to be a string but it must adhere to the format of a valid UUID. To achieve this, I have i ...

Angular utilizes ZoneAwarePromise rather than a plain String output

I expected the giver code to return a string, but it is returning ZoneAwarePromise. Within the service: getCoveredPeriod() { let loanDetails = this.getLoanDetails().toPromise(); loanDetails.then((res: any) => { const coveredPeriodStart ...

Is there a way to specify patternProperties in a JSON schema and then map it to a TypeScript interface?

I'm in the process of developing a TypeScript interface that corresponds to a JSON schema. The specific field in my JSON schema is as follows: "styles": { "title": "Style Definitions", &qu ...

Tips for effectively integrating an admin panel into an Angular project

After building a website with Angular 6, I now need to develop an admin panel to make the site dynamic. What would be the best approach for this task - creating a separate Angular app for the admin panel or incorporating it within the existing website ap ...

Creating a Loading Sign with a Button Component in React

Request Description: In my form, I have a button that triggers a submission to the backend. While the request is processing, I want the button to display a loading indicator instead of the usual text. Once the request is complete, I need the form to disap ...

TSLint has detected an error: the name 'Observable' has been shadowed

When I run tslint, I am encountering an error that was not present before. It reads as follows: ERROR: C:/...path..to../observable-debug-operator.ts[27, 13]: Shadowed name: 'Observable' I recently implemented a debug operator to my Observable b ...

Can you explain Angular's "rule of unidirectional data flow" to me?

The concept of Angular's "unidirectional data flow rule" is mentioned throughout various sections of the Angular documentation, yet a clear and concise definition of this rule is nowhere to be found. After thorough research, I discovered two somewhat ...

Trying to enter the function, but it exits without executing

I'm facing an issue with my function that involves making multiple calls to an observer. I need the function to wait until all the calls are complete before returning. I attempted putting the return statement inside the subscribe method, but it result ...

Leveraging TypeScript to share information between directives in AngularJS through asynchronous calls

Although I've found some scattered information on how to tackle this issue, I haven't been able to find a solid solution. In my AngularJS application, I have an asynchronous call that fetches data from a server and I need to store it in a variab ...

Scroll to the top on every Angular 5 route change

Currently, I am utilizing Angular 5 for my project. Within the dashboard interface, there are various sections with varying amounts of content. Some sections contain only a small amount of information, while others have large amounts of content. However, w ...

Angular 4 has the capability to automatically log out in all tabs when a user logs out in one open tab

I am looking to implement a feature where I automatically log out from all open tabs when logging out from one tab. Currently, I am storing a jwt token in localStorage upon login and removing the token upon logout. Any suggestions on how I can utilize st ...