Создать многошаговую форму без углового интерфейса - PullRequest
1 голос
/ 28 июня 2019

пожалуйста, посмотрите описание изображения здесь Мне нужно создать многошаговую форму без использования Angular UI Router и углового материала.может ли кто-нибудь мне помочь.

<div class="wizard">
  <a routerLinkActive="active" [routerLink]="['/customer-dashboard/customer-information/information-form']" [routerLinkActiveOptions]="{exact: true}">
      Submit Information
  </a>
  <a [class.disabled]="idTab" routerLinkActive="active" [routerLink]="['/customer-dashboard/customer-information/id-form']" [routerLinkActiveOptions]="{exact: false}">
      Submit Id
  </a>
  <a  routerLinkActive="active" [routerLink]="['/customer-dashboard/customer-information/verify-identity']" [routerLinkActiveOptions]="{exact: false}">
      Verify Identity
  </a>
  <a routerLinkActive="active" [routerLink]="['/customer-dashboard/customer-information/final-validation']" [routerLinkActiveOptions]="{exact: false}">
    Final Validation
  </a>
  <a routerLinkActive="active" [routerLink]="['/customer-dashboard/customer-information/approval']" [routerLinkActiveOptions]="{exact: false}">
    Approval
  </a>
</div>

1 Ответ

0 голосов
/ 30 июня 2019

работает CodesandBox

app.component.html

<div>
  <span class="state-container" [ngStyle]="state === 1 && {'color': 'red'}"
    >state 1</span
  >
  <span class="state-container" [ngStyle]="state === 2 && {'color': 'red'}"
    >state 2</span
  >
  <span class="state-container" [ngStyle]="state === 3 && {'color': 'red'}"
    >state 3</span
  >
</div>
<div *ngIf="state === 1">
  <form #f1="ngForm" (ngSubmit)="onSubmit(user)" novalidate>
    <label for="name">Name</label>
    <input name="name" id="name" [(ngModel)]="user.name" />
    <label for="family">Family</label>
    <input name="family" id="family" [(ngModel)]="user.family" />
    <button (click)="next(user)">Next</button>
  </form>
</div>
<div *ngIf="state === 2">
  <form #f2="ngForm" (ngSubmit)="onSubmit(user)" novalidate>
    <label for="address">Address</label>
    <input name="address" id="family" [(ngModel)]="user.address" />
    <button (click)="back()">Back</button>
    <button (click)="next(user)">Next</button>
  </form>
</div>
<div *ngIf="state === 3">
  <p>The End</p>

  <button (click)="back()">Back</button>
  <button (click)="reset()">Reset</button>
  <button (click)="save(user)">Save</button>
</div>

app.component.ts

import { Component, OnInit } from "@angular/core";
interface User {
  name: string;
  family: string;
  address: string;
}
@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.css"]
})
export class AppComponent implements OnInit {
  title = "CodeSandbox";
  state = 1;
  user: User;
  ngOnInit() {
    this.user = {
      name: "",
      family: "",
      address: ""
    };
  }
  save(user: User) {
    alert("Final Result:\n\n" + JSON.stringify(user));
  }
  next(user: User) {
    ++this.state;
    alert(JSON.stringify(user));
  }
  back() {
    --this.state;
  }
  reset() {
    this.state = 1;
    this.user = {
      name: "",
      family: "",
      address: ""
    };
  }
}

app.module.ts

import { BrowserModule } from "@angular/platform-browser";
import { NgModule } from "@angular/core";

import { AppComponent } from "./app.component";
import { FormsModule } from "@angular/forms";

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, FormsModule],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {}

Лично я не рекомендую такой подход.Просто помните: если вы не сохраните данные и не обновите страницу, ваши данные исчезнут.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...