简体   繁体   English

如何重置为第一步 Angular 步进器 CDK?

[英]How to reset to step one Angular stepper CDK?

I have a list of item and each item have a button to show a modal stepper.我有一个项目列表,每个项目都有一个按钮来显示模态步进器。 When I click button of item 1 with id="1" and click stepper next to step 2 for example then close modal by click cancel on modal.例如,当我单击带有 id="1" 的项目 1 的按钮并单击步骤 2 旁边的步进器时,然后通过单击模态上的取消来关闭模态。 Afterward I click open modal item 2 with id="2 but the stepper it still remain step 2 I want it reset to step 1之后我点击打开模式项 2 id="2 但步进器它仍然保持第 2 步我希望它重置为第 1 步

<app-ui-modal
  [(show)]="isShowModalStepper"
  [hiddenHeader]="false"
  [hiddenFooter]="true"
  [paddingNone]="true"
  [width]="60"
  [height]="">
  <div ui-modal-body>
    <app-stepper #cdkStepper [linear]="true">
      <cdk-step label="step 1" [editable]="true" [stepControl]="frmConfirmRight" [optional]="false">
        <ng-template cdkStepLabel>
          <span>STEP 1</span>
        </ng-template>
        <form [formGroup]="frmConfirmRight">
          <div class="my-4">
            <p class="text-center text-3xl text-orange-regular">Hello world</p>
            <div class="flex justify-center my-2">
              <app-ui-input-container>
                <app-ui-input-checkbox-wrapper label="Agree">
                  <input appUIInputCheckbox type="checkbox"
                    formControlName="confirm">
                </app-ui-input-checkbox-wrapper>
              </app-ui-input-container>
            </div>
          </div>
          <footer class="my-4 flex-center">
            <!-- Close modal -->
            <button class="mx-1 w-24" [size]="'md'" app-ui-button [variant]="'default'"
              (click)="isShowExclusion = !isShowExclusion">
              Cancel
            </button>
            <!-- Next step -->
            <button class="mx-1 w-24"
              [size]="'md'"
              [disabled]="frmConfirmRight.invalid"
              app-ui-button
              [variant]="'primary'"
              cdkStepperNext>
              Next step
            </button>
          </footer>
        </form>
      </cdk-step>

Any help is appreciated.任何帮助表示赞赏。 Thanks you!谢谢!

Reference your stepper and then call the following method at the appropriate time (this implementation assumes you are referencing the stepper from a parent component):引用您的步进器,然后在适当的时间调用以下方法(此实现假设您正在从父组件引用步进器):


@ViewChild('cdkStepper') cdkStepper: MatStepper | undefined;

someMethod(){
  if(this.cdkStepper){
    this.cdkStepper.reset()
  }
}

After a while I found过了一会儿我发现

<button class="mx-1 w-24" [size]="'md'" app-ui-button [variant]="'default'"
   (click)="isShowModalStepper = !isShowModalStepper; cdkStepper.reset()">
    Cancel
</button>

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

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