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

CdkStepper error when binding to selectedIndex #8031

Closed
rpd10 opened this issue Oct 25, 2017 · 2 comments · Fixed by #8035
Closed

CdkStepper error when binding to selectedIndex #8031

rpd10 opened this issue Oct 25, 2017 · 2 comments · Fixed by #8035
Assignees

Comments

@rpd10
Copy link

rpd10 commented Oct 25, 2017

Bug, feature request, or proposal:

Bug

What is the expected behavior?

Since there is not currently a responsive stepper, I'm working with hiding/showing vertical and horizontal steppers based on the viewport size. When the viewport resizes and the steppers are swapped out, I need to set the selected index on the stepper that is coming into view. I'm doing that by listening to selectionChange event on the stepper, storing the index (defaulting to 0), and binding to it on both steppers.

What is the current behavior?

When Angular creates the stepper the first time, the bound index is set to 0. The CdkStepper set selectedIndex function is calling _anyControlsInvalid(), which has a NPE when checking for steps that have not yet been created:

TypeError: Cannot read property 'toArray' of undefined
    at MatHorizontalStepper.CdkStepper._anyControlsInvalid (stepper.es5.js:373)
    at MatHorizontalStepper.set [as selectedIndex] (stepper.es5.js:206)

What are the steps to reproduce?

https://stackblitz.com/edit/angular-material2-issue-ggc2sf

Error shows in console

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

I can see additional uses for binding to selectedIndex, for example if you already know the user has completed some steps and you want to start them further along.

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

Material beta 12

Is there anything else we should know?

@crisbeto crisbeto self-assigned this Oct 25, 2017
@rpd10
Copy link
Author

rpd10 commented Oct 25, 2017

I'll try to work up a pull request for this, seems pretty simple.

crisbeto added a commit to crisbeto/material2 that referenced this issue Oct 25, 2017
Fixes an error that is thrown if the `selectedIndex` is set before the steps are initialized.

Fixes angular#8031.
andrewseguin pushed a commit that referenced this issue Nov 2, 2017
Fixes an error that is thrown if the `selectedIndex` is set before the steps are initialized.

Fixes #8031.
@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 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants