question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Duration is missing from MdSnackBar

See original GitHub issue

Bug, feature request, or proposal:

Bug

What is the expected behavior?

According to docs, there should be a duration property in MdSnackBarConfig type

What is the current behavior?

There is not a duration property in MdSnackBarConfig

Throws:

Argument of type '{ duration: number; }' is not assignable to parameter of type 'MdSnackBarConfig'.
Object literal may only specify known properties, and 'duration' does not exist in type 'MdSnackBarConfig'.

What are the steps to reproduce?

Try to add a duration property to the configuration object when open a SnackBar.

Which versions of Angular, Material, OS, browsers are affected?

Angular: 2.2.1 Material: alpha-10 OS: Windows 10 AU

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
valdestroncommented, Nov 30, 2016

Temporary workaround:

import { Injectable } from '@angular/core';
import { MdSnackBarRef, MdSnackBar, MdSnackBarConfig } from '@angular/material';

@Injectable()
export class AlertsService {
	public snackBarRef: MdSnackBarRef<any>;
	
	constructor(
		private snackBar: MdSnackBar
	) { }

	showMsg(type: string, msg: string, haveAction: boolean, actionLabel: string, duration: number) {
		const config: any = new MdSnackBarConfig(); // <-- https://github.com/angular/material2/issues/2020
		this.snackBarRef = this.snackBar.open(msg, haveAction && actionLabel, config);

		setTimeout(() => {
			this.snackBarRef.dismiss();
		}, (duration || 1) * 1000);
	}
}
0reactions
angular-automatic-lock-bot[bot]commented, Sep 5, 2019

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Duration is missing from MdSnackBar · Issue #2020 - GitHub
Try to add a duration property to the configuration object when open a SnackBar. Which versions of Angular, Material, OS, browsers are affected?...
Read more >
How can I set duration of a snack-bar in angular2 (material2)
With angular material 2.0.0-alpha.11, You can now add timeout to snackbar. open() { let config = new MdSnackBarConfig(); config.duration ...
Read more >
Snackbars - Material Design
Only one snackbar may be displayed at a time. ... Snackbars appear temporarily, and disappear on their own without requiring user input to...
Read more >
angular/material2 - Gitter
Has anyone got snackbars working from inside of a route resolver? I have routes that are defined as follows: export const ROUTES: Routes...
Read more >
Snackbar | Angular Material
A snackbar can contain a single action with an additional optional "dismiss" or "cancel" action. Avoid setting a duration for snackbars that have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found