admin管理员组文章数量:1355642
The issue I'm having is that, the snackbar ponent, when initialised, is attached outside of cdk-global-overlay-wrapper (Which is within cdk-overlay-container)
Which makes it visible for a split second, in the middle of the screen
It then disappears and re-attaches itself within cdk-global-overlay-wrapper and scrolls from bottom as it should.
Any ideas how to change this?
The issue I'm having is that, the snackbar ponent, when initialised, is attached outside of cdk-global-overlay-wrapper (Which is within cdk-overlay-container)
Which makes it visible for a split second, in the middle of the screen
It then disappears and re-attaches itself within cdk-global-overlay-wrapper and scrolls from bottom as it should.
Any ideas how to change this?
Share Improve this question asked Jan 24, 2018 at 12:58 RasMasonRasMason 2,2125 gold badges36 silver badges60 bronze badges1 Answer
Reset to default 10I had a similar issue where MatSnackBar existed outside the Angular zone which breaks it's interaction with Angular's lifecycle hooks.
This was only happenng when the snackBar.open() callstack was originally exicuted by a 3rd party service (in my case SignalR).
I fixed it by wrapping the snackBar.open()
mand in a NgZone.run()
task within my ponent. This allows you to reenter the Angular zone from a task that was exicuted from outside.
example:
import { Component, NgZone } from '@angular/core';
import { MatSnackBar } from '@angular/material';
@Component({
selector: 'example',
templateUrl: './example.ponent.html',
styleUrls: ['./example.ponent.scss']
})
export class ExampleComponent {
constructor( private snackBar: MatSnackBar, private zone: NgZone ) { }
showSnackBar() {
this.zone.run(() => {
this.snackBar.open("message", "action");
});
}
}
This is not exactly the problem you described, but it may help.
本文标签: javascriptAngular 5 Material snackbarStack Overflow
版权声明:本文标题:javascript - Angular 5 Material snackbar - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744054103a2582956.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论