Topic: stepper ngif directive breaks behaviour

Herzog free asked 5 years ago


When using a ngif directive to hide following steppers, the stepper breaks and all functionality like stepper.next() in Component won't work. The hidden steps will not be included in the stepper.steps array. Whithout the ngif, everything works as expected

Regards Tom


Damian Gemza staff answered 5 years ago


Dear @Herzog

Could you please provide me with the code which is not working for you? I have tried to reproduce your desired behavior, and for me, everything is working fine.

Please take a look at the below code:

.html:

<div class="container">
  <div class="row">
    <div class="col-md-6 mx-auto my-5">
      <mdb-stepper #stepper [linear]="true">
        <mdb-step name="Step 1" [stepForm]="firstFormGroup">
          <form [formGroup]="firstFormGroup">
            <div class="md-form">
              <input type="text" class="form-control" mdbInput mdbValidate formControlName="email">
              <label for="">Email</label>
              <mdb-error *ngIf="email.invalid && (email.dirty || email.touched)">Input invalid</mdb-error>
              <mdb-success *ngIf="email.valid && (email.dirty || email.touched)">Input valid</mdb-success>
            </div>
          </form>
          <button mdbBtn size="sm" color="primary" (click)="stepper.next()">CONTINUE</button>
        </mdb-step>
        <mdb-step name="Step 2" [stepForm]="secondFormGroup" *ngIf="email.valid">
          <form [formGroup]="secondFormGroup">
            <div class="md-form">
              <input type="password" class="form-control" mdbInput mdbValidate formControlName="password">
              <label for="">Password</label>
              <mdb-error *ngIf="password.invalid && (password.dirty || password.touched)">Input invalid</mdb-error>
              <mdb-success *ngIf="password.valid && (password.dirty || password.touched)">Input valid</mdb-success>
            </div>
          </form>
          <button mdbBtn size="sm" color="primary" (click)="stepper.next()">CONTINUE</button>
          <button mdbBtn size="sm" color="secondary" (click)="stepper.previous()">BACK</button>
        </mdb-step>
        <mdb-step name="Step 3" label="Step 3 label" *ngIf="password.valid">
          <p class="pl-2">Finish!</p>
          <div class="step-actions">
            <button mdbBtn  size="sm" color="primary" (click)="onSubmit()">SUBMIT</button>
          </div>
        </mdb-step>
      </mdb-stepper>
    </div>
  </div>
</div>

.ts:

firstFormGroup: FormGroup;
  secondFormGroup: FormGroup;

  ngOnInit() {
    this.firstFormGroup = new FormGroup({
      email: new FormControl('', [Validators.required, Validators.email])
    });
    this.secondFormGroup = new FormGroup({
      password: new FormControl('', Validators.required)
    });
  }

  get email() { return this.firstFormGroup.get('email'); }
  get password() { return this.secondFormGroup.get('password'); }

  onSubmit() {
    // do something here
  }

Best Regards,

Damian


jasmine.12 free commented 1 year ago

how to make condition if steppernext have two button my stepper in modal and i want to show 2 content in my modal but with 2 butoon



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: 7.5.1
  • Device: Desktop
  • Browser: all
  • OS: Windows
  • Provided sample code: No
  • Provided link: No