angular-material - Angular Material Stepper 中的已完成属性似乎无法按预期工作
问题描述
这是这种行为的堆叠闪电战。我期望看到的是,当单击完成按钮时,第一步完成,因此图标将变为“10”。但是,并没有什么变化,甚至当移动到第二步时,图标也是“创建”。我是否误解了该completed
属性应该如何工作,或者材料代码中是否存在错误?
解决方案
这里有几个问题:
图标是“创建”:
步进器依赖于材质图标。将材料图标添加到您的项目中,'cre'
图标就消失了。
此外,创建/编辑图标是已完成步骤的正常行为。如果您希望将步骤标记为完成,则必须设置completed=true
和editable = false
另一个问题是使用let-index="index"
. V5 文档中对此没有任何内容。(而且您的 stackblitz 正在使用 V5)。
如果您有可能升级到 V6,那么就有可能满足您的要求。我为这种行为创建了一个堆栈闪电战。
组件.ts
import { Component, ViewChild } from '@angular/core';
import { MatHorizontalStepper } from '@angular/material';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
@ViewChild(MatHorizontalStepper) stepper: MatHorizontalStepper;
complete() {
this.stepper.selected.completed = true;
this.stepper.selected.editable = false;
this.stepper.next();
}
}
组件.html
<mat-horizontal-stepper linear id="stepper">
<ng-template matStepperIcon="done" let-index="index">
{{(index+1) * 10}}
</ng-template>
<mat-step label="Step 1">
<p>Step 1</p>
<button mat-button (click)="complete()" mat-raised-button color="primary">Complete</button>
</mat-step>
<mat-step label="Step 2">
<h3>Step 2</h3>
<button mat-button (click)="complete()" mat-raised-button color="primary">Complete</button>
</mat-step>
<mat-step label="Step 3">
<h3>Step 3</h3>
<button mat-button (click)="complete()" mat-raised-button color="primary">Complete</button>
</mat-step>
</mat-horizontal-stepper>
推荐阅读
- android - Gson Post 方法
- wordpress - 在wordpress的菜单栏中滑动带有标题的图像
- laravel - 使用 Laravel 5.5 通过 amazon ses 发送邮件以进行用户验证
- javascript - 按类型过滤数组对象并将键值与对象进行比较
- java - karaf 控制台未在 opendaylight 启动原型中启动
- kubernetes - 是否可以在 kubernetes 中运行多个嵌套的 kubernetes 集群(k-in-k)
- python-3.x - 从元组组合对列表中挑选,使得每个元组元素至少出现两次
- php - 如何从 codeIgniter 的打印页面中删除搜索框和分页?
- excel - 使用 VBA 从 DIV 中检索数据
- reactjs - 如何增加 react-native Slider 组件的高度?