Angular Material SnackBar not responding to the `onAction()` method

I'm encountering an issue with the Angular Material SnackBar's onAction() method. It seems that it is not triggering after the button is clicked. Even though I have subscribed to the onAction, afterDismissed, and afterOpened methods, only the latter two are being triggered. Has anyone else faced this problem? It started occurring after updating Angular from version 9 to 11.

constructor(public snackBar: MatSnackBar) {}

private openSnackBar() {
  let mySnackBar: MatSnackBarRef<TextOnlySnackBar> = this.snackBar.open('Message', 'Close');
    mySnackBar.afterDismissed().subscribe((matSnackBarDismiss: MatSnackBarDismiss) => {
      console.log('afterDismissed');
    });
    mySnackBar.onAction().subscribe(() => {
      console.log('onAction');
      mySnackBar.dismiss();
    });
    mySnackBar.afterOpened().subscribe(() => {
      console.log('afterOpened');
    });
  }
}

Answer №1

The issue stemmed from an internal CSS problem, potentially caused by the removal of a CSS property (most likely pointer-events) during an Angular update. I managed to resolve it by adjusting the local CSS code.

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

Angular7 is throwing an error stating that the type 'Observable <Object>' cannot be assigned to the type 'Observable <Group> []'

I encountered this issue when I tried to assign an observable to the class: The type 'Observable ' is not compatible with the type 'Observable '. Type 'Object' lacks properties found in 'Grupo []': length, pop, push ...

Error: Your call to the "useFormState" function does not match any available

I am fairly new to web application development and I'm facing an issue with the useFormState function. I am currently working on building an edit form for database entries, but the code that previously worked is now throwing an error stating that ther ...

"Exploring the power of Knex in combination with Typescript and Electron. However, encountering node_module errors

I currently have a functioning Electron application that utilizes Typescript. The main.ts file is specifically for the main process. import { app, BrowserWindow } from 'electron'; import * as path from 'path'; import * as url from &apos ...

Extracting data from the Sanity API response in JSON format using Typescript

Struggling with extracting information from a Sanity Client API call and decoding the resulting JSON data. Can someone guide me on how to access specific values? Below is the output of the API call: [ { slug: { current: "test-post", _type: ...

The specified property is not present on the given type

I am receiving data from an API, and I have defined its structure like this interface DailyData { dt: number; sunrise: number; sunset: number; moonrise: number; moonset: number; moon_phase: number; temp: {day: number, eve: number, max: number ...

Using the p-multiSelect component in Primeng for Angular 2

Within the user.component.html template, I am utilizing a Primeng component. <p-multiSelect name="roles_id" [(ngModel)]="selectedRoles" [options]="user.roles"></p-multiSelect> When loading the input data, how can ...

Tips for effectively managing asynchronous tasks

I keep getting different numbers every time my code runs. Can you tell me if I'm doing this the right way? Here's the code: export class GetPlanetsService { url='https://swapi.co/api/planets/?page='; planets:Planet[]=[]; headers: ...

Troubleshooting TypeScript window augmentation not functioning in individual modules

I would like to extend the window object with a new property. This can be achieved by adding the following code: // global.d.ts import { IConfig } from './src/models'; export {}; declare global { interface Window { _env: IConfig; ...

Currently running typescript-json-schema with an undefined root type

Trying to execute the command typescript-json-schema --noExtraProps --required --refs false -o ./types.schema.json ./tsconfig.json * using the typescript-json-schema npm package results in an error: Error: Not supported: root type undefined at JsonSc ...

Patiently await the observable to receive an array of data

Although there have been numerous discussions on this topic, I am still struggling to find a solution that works well for me. If you come across one, please do share it with me. Currently, I am fetching data from an API and converting it into an array of ...

Retrieving the current user in the authentication service with Angular 8

What the backend api is returning I am attempting to retrieve the current user as an observable in the authentication service, so that I can show the user name in any component that subscribes to the authService. Everything seems to be working well, exce ...

When transforming a function into a custom command, the expected outcome may vary

There is a function that retrieves all CSS properties and values of an element: function fetchAllCssPropertiesAndValues(element: Element) { const style = window.getComputedStyle(element) const propertiesAndValues = {} for (let i = 0; i < st ...

What design should be used for a class with two interconnected attributes?

I am looking to develop a customizable macro item that can be edited by the user. Each macro item will have a defined type and event value. There are three types of items: pressKey, releaseKey, and delayInMs. For pressKeyEvent and releaseKeyEvent, I wan ...

Having trouble with Axios cross-origin POST request CORS error in React / Typescript, even after trying all the common solutions

I am encountering a CORS error in my React / Typescript project when trying to make a POST request using Axios. The project uses a Node.js / Express backend. Despite researching common CORS errors and reading highly-rated posts on the topic, I have been un ...

Customizing the header template in ag-Grid for Angular 2

I have implemented ag-grid within an ng2 component. Now, I am trying to make the first header a checkbox with the parent functionality. How can I achieve this from the container component? ag-grid.component @Component({ moduleId: module.id, selecto ...

Troubleshoot: Issue with injecting external component into another component using directive in Angular 2

I need the child component template to be loaded into the parent component template. (calling them child and parent for simplicity) Here is the child component: import {Component,Directive, ElementRef, Input} from '@angular/core'; import {IONIC ...

What is the proper way to define an array of objects in TypeScript?

In search of a way to define a function that accepts an array of unspecified object types, known as "anonymous types." I want to enforce strict typing with TypeScript. The objects in the array all have properties like name, price, and description. bagTotal ...

Challenge with Dependency Injection in the Handlers of NestJS CQRS repositories

As a newcomer to nodejs, I am currently delving into the implementation of NestJS's CQRS 'recipe'. In my service, I have a Request scoped with the injection of QueryBus: @Injectable({scope: Scope.REQUEST}) export class CustomerService { co ...

Combining Firebase analytics with an Ionic 3 application using the Ionic Native plugin

I placed the GoogleService-Info.plist file at the root of the app folder, not in the platforms/ios/ directory. When I tried to build the app in Xcode, an error occurred in the following file: FirebaseAnalyticsPlugin.m: [FIROptions defaultOptions].deepLin ...

Leveraging the power of Angular2 and redux through the seamless integration of

I recently started experimenting with angular2 and redux. However, I encountered an issue while trying to bootstrap my main app by injecting NgRedux and NgReduxRouter: There was an error loading http://localhost:4200/ng2-redux/index.js as "ng2-redux" from ...