简体   繁体   English

如何在 Angular Material Stepper 中禁用一个步骤?

[英]How to disable a step in Angular Material Stepper?

I have 3 steps in an Angular Material horizontal stepper.我在 Angular Material 水平步进器中有 3 个步骤。 I want to enable the first 2 by default but have the 3 step disabled (but not hidden).我想默认启用前 2 步,但禁用 3 步(但不隐藏)。

These steps don't necessary have form values which decide if the current step is valid or not.这些步骤不必具有决定当前步骤是否有效的表单值。 There are a series of backend calls that occur which decide if the current step is valid or not.有一系列后端调用决定当前步骤是否有效。 The linear mode option looks like it would work but it seems to rely on their being a form with required values in order to determine if the form is valid or not.线性模式选项看起来可以工作,但它似乎依赖于它们是具有所需值的表单,以确定表单是否有效。 I don't have a form but still want the same type of functionality.我没有表格,但仍然想要相同类型的功能。 Any ideas?有任何想法吗?

https://stackblitz.com/angular/dqllekdmmly?file=app%2Fstepper-overview-example.ts https://stackblitz.com/angular/dqllekdmmly?file=app%2Fstepper-overview-example.ts

You don't have to use forms to use the stepper. 您无需使用表格即可使用步进器。 Note the following from the Angular Material documentation on the linear stepper: 请注意线性步进器上“ 角度材料”文档中的以下内容:

Alternatively, if you don't want to use the Angular forms, you can pass in the completed property to each of the steps which won't allow the user to continue until it becomes true. 另外,如果您不想使用Angular表单,则可以将completed属性传递给每个步骤,这些步骤将不允许用户继续操作直到它变为true。

Without forms, you simply need to use your own logic and the stepper features to implement state etc. 没有表单,您只需要使用自己的逻辑和步进功能来实现状态等。

To achieve this , You can disable the mat-stepper-header navigation. 为此,您可以禁用mat-stepper-header导航。

And use click event to step ahead. 并使用click event向前迈进。

To disable the mat-stepper-header navigation use this css 要禁用mat-stepper-header导航,请使用此CSS

.mat-step-header {
                pointer-events: none !important;
     }

This worked absolutely fine . 这绝对好用。

Thank You 谢谢

i need to stop thechanges on previous completed step我需要停止上一个已完成步骤的更改

Use the Completed Stepp, using any condition to set it as true or false , this is the info in Material Angular使用 Completed Stepp,使用任何条件将其设置为truefalse ,这是 Material Angular 中的信息

https://material.angular.io/components/stepper/overview#completed-step https://material.angular.io/components/stepper/overview#completed-step

Completed step完成步骤
By default, the completed attribute of a step returns true if the step is valid (in case of linear stepper) and the user has interacted with the step.默认情况下,如果步骤有效(在线性步进器的情况下)并且用户已与步骤交互,则步骤的完成属性返回 true。 The user, however, can also override this default completed behavior by setting the completed attribute as needed.然而,用户也可以通过根据需要设置完成属性来覆盖这个默认的完成行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM