components icon indicating copy to clipboard operation
components copied to clipboard

SnackBar openFromComponent fully initialize the component directly

Open tchandelle opened this issue 9 years ago • 2 comments

Bug, feature request, or proposal:

Bug

What is the expected behavior?

https://plnkr.co/edit/8lK1vYhdgYf8ynmtz1a0?p=preview

On 2.0.0-beta.10, when clicking Pizza party, console should display

Pizza Before-Party
Pizza Party ctor
Pizza After-Party
Pizza Party OnInit

What is the current behavior?

https://plnkr.co/edit/tMhP1gRJta8VyZiGSit6?p=preview

On 2.0.0-beta.11, when clicking Pizza party, console will display

Pizza Before-Party
Pizza Party ctor
Pizza Party OnInit
Pizza After-Party

The OnInit hook is called directly after the constructor.

What is the use-case or motivation for changing an existing behavior?

      const ref: MdSnackBarRef<MyComponent> =
          this.snackBar.openFromComponent(MyComponent, {
            duration: 10000
          });
      ref.instance.data = data;

This does not work anymore because MyComponent is already displayed before I was able to set the data member, which is used in its view.

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

Angular 4.4.4 Material 2.0.0-beta.11

tchandelle avatar Oct 02 '17 14:10 tchandelle

This change is the result of #6649

The allow for the snackbar to be OnPush, change detection must be manually called to start the entrance of the snackbar.

Specific to the issue you are seeing of setting the data in your instance, you can pass the data into your component via the MatSnackBarConfig. You can see an example of this being done in the SimpleSnackBar here

josephperrott avatar Nov 20 '17 21:11 josephperrott

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.