繁体   English   中英

创建不带角度ui路由器的多步表单

[英]Create multistep form without angular ui router

请在此处查看图像描述,我需要创建一个多步骤表单而不使用Angular UI Router和Angular材质。 谁能帮我。

<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>

工作代码箱

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 {}

我个人不推荐这种方法。 请记住,如果您不保存数据并刷新页面,则数据将丢失。

暂无
暂无

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

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