Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MatButtonToggle errors with Ivy enabled #16471

Closed
bampakoa opened this issue Jul 8, 2019 · 6 comments · Fixed by #16587
Closed

MatButtonToggle errors with Ivy enabled #16471

bampakoa opened this issue Jul 8, 2019 · 6 comments · Fixed by #16587
Assignees
Labels
P2 The issue is important to a large percentage of users, with a workaround

Comments

@bampakoa
Copy link
Contributor

bampakoa commented Jul 8, 2019

The MatButtonToggle component throws several errors in ng serve with Ivy compiler enabled.

Reproduction

Not able to reproduct with Stackblitz

Expected Behavior

ng serve should not throw any errors

Actual Behavior

ng serve throws the following errors:

{
  message: "Cannot read property 'selected' of undefined",
  name: 'TypeError',
  stack:
   "TypeError: Cannot read property 'selected' of undefined
      at MatButtonToggleGroup.get selected [as selected]
      at MatButtonToggleGroup._syncButtonToggle
      at MatButtonToggle.set checked [as checked]
      at setInputsFromAttrs
      at postProcessDirective
      at instantiateAllDirectives 
      at createDirectivesAndLocals
      at ɵɵelementStart"
}
{
  message: "Cannot read property 'buttonId' of null",
  name: 'TypeError',
  stack:
   "TypeError: Cannot read property 'buttonId' of null
      at MatButtonToggle_Template
      at executeTemplate
      at checkView
      at componentRefresh
      at refreshChildComponents
      at refreshDescendantViews
      at renderEmbeddedTemplate
      at refreshDynamicEmbeddedViews 
      at refreshDescendantViews
      at checkView"
}

Environment

Angular CLI: 8.1.0
Node: 10.15.3
OS: win32 x64
Angular: 8.2.0-next.0
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package Version

@angular-devkit/architect 0.801.0
@angular-devkit/build-angular 0.801.0
@angular-devkit/build-optimizer 0.801.0
@angular-devkit/build-webpack 0.801.0
@angular-devkit/core 8.1.0
@angular-devkit/schematics 8.1.0
@angular/cdk 8.0.2
@angular/cli 8.1.0
@angular/material 8.0.2
@ngtools/webpack 8.1.0
@schematics/angular 8.1.0
@schematics/update 0.801.0
rxjs 6.5.2
typescript 3.4.5
webpack 4.35.2

@crisbeto
Copy link
Member

crisbeto commented Jul 8, 2019

Can you post what your template looks like? Otherwise it's difficult to investigate.

@bampakoa
Copy link
Contributor Author

bampakoa commented Jul 8, 2019

@crisbeto thanks very much for your prompt reply. Here is my template. Not something complicated:

  <mat-drawer mode="side" opened>
      <mat-button-toggle-group vertical>
        <mat-button-toggle checked="true" title="Layers" routerLink="/dashboard">
          <mat-icon>layers</mat-icon>
        </mat-button-toggle>
        <mat-button-toggle title="Collections" routerLink="collections">
          <mat-icon>collections</mat-icon>
        </mat-button-toggle>
        <mat-button-toggle title="Projections" routerLink="projections">
          <mat-icon>map</mat-icon>
        </mat-button-toggle>
        <mat-button-toggle title="Settings" routerLink="settings">
          <mat-icon>settings</mat-icon>
        </mat-button-toggle>
      </mat-button-toggle-group>
      <router-outlet></router-outlet>
   </mat-drawer>

@Qocotzxin
Copy link

@crisbeto @bampakoa I'm having same error on testing. Very simple scenario, no conditional neither iteerations, just one simple toggle group.
toggle-button-error

@crisbeto crisbeto self-assigned this Jul 22, 2019
@crisbeto crisbeto added has pr P2 The issue is important to a large percentage of users, with a workaround labels Jul 22, 2019
crisbeto added a commit to crisbeto/material2 that referenced this issue Jul 22, 2019
…e in Ivy

Fixes the button toggle throwing an error under Ivy, if its `checked` value is set via a static attribute (e.g. `<mat-button-toggle checked>`). The issue comes from the fact that in Ivy static inputs are set during creation, which means that the selection model isn't initialized yet.

Fixes angular#16471.
@crisbeto
Copy link
Member

It'll be fixed by #16587. Until the fix is released, you should be able to work around it by binding to checked like this: <mat-button-toggle [checked]="true">.

crisbeto added a commit to crisbeto/material2 that referenced this issue Jul 22, 2019
…e in Ivy

Fixes the button toggle throwing an error under Ivy, if its `checked` value is set via a static attribute (e.g. `<mat-button-toggle checked>`). The issue comes from the fact that in Ivy static inputs are set during creation, which means that the selection model isn't initialized yet.

Fixes angular#16471.
jelbourn pushed a commit that referenced this issue Jul 25, 2019
…e in Ivy (#16587)

Fixes the button toggle throwing an error under Ivy, if its `checked` value is set via a static attribute (e.g. `<mat-button-toggle checked>`). The issue comes from the fact that in Ivy static inputs are set during creation, which means that the selection model isn't initialized yet.

Fixes #16471.
@ramyasingamsetti
Copy link

ramyasingamsetti commented Jul 25, 2019

Hello, still i am facing same issue while running unit tests.
below is my code.

          <mat-button-toggle-group #toggleid="matButtonToggleGroup" value="value1" 
                        (change)="change(toggleid.value)">

           <mat-button-toggle value="value1" checked="true">value1</mat-button-toggle>
            <mat-button-toggle value="value2">value2</mat-button-toggle>
            <mat-button-toggle value="value3">value3</mat-button-toggle>
       </mat-button-toggle-group>

andrewseguin pushed a commit that referenced this issue Jul 29, 2019
…e in Ivy (#16587)

Fixes the button toggle throwing an error under Ivy, if its `checked` value is set via a static attribute (e.g. `<mat-button-toggle checked>`). The issue comes from the fact that in Ivy static inputs are set during creation, which means that the selection model isn't initialized yet.

Fixes #16471.
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants