最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to set only two input fields in a row in Angular Form - Stack Overflow

programmeradmin1浏览0评论

I am new to Angular development, trying to create a registration form where I need to have two columns in a row , like Firstname ,Lastname in one row followed by Phone,Email and Password,Confirm password.I am using mat-form-field, but when I add a new field all are placed next to each other as shown in below picture, I want them in next line.

current form image

ponent.html

<div class="container">
  <div class="row">
    <div class="registration-form col-md-6" style="max-width: -webkit-fill-available;">
      <div class="main-div" style="width: inherit;text-align: center">
        <div class="panel">
          <h2> Registration Form</h2>
        </div>
        <div class="alert alert-danger" *ngIf="errorMsg">
          {{errorMsg}}
        </div>
        <form #registartionForm="ngForm" (ngSubmit)="onSubmit()" novalidate>
          <mat-form-field appearance="outline">
            <mat-label>First Name</mat-label>
            <input matInput placeholder="Placeholder">
          </mat-form-field>
          &nbsp;
          <mat-form-field appearance="outline">
            <mat-label>Last Name</mat-label>
            <input matInput placeholder="Placeholder">
          </mat-form-field>
          &nbsp;
          <mat-form-field appearance="outline">
            <mat-label>Email</mat-label>
            <input matInput placeholder="Placeholder">
          </mat-form-field>
          &nbsp;
          <mat-form-field appearance="outline">
            <mat-label>Phone Number</mat-label>
            <input matInput placeholder="Placeholder">
          </mat-form-field>
          &nbsp;
          <mat-form-field appearance="outline">
            <mat-label>Password</mat-label>
            <input type="password" matInput placeholder="Placeholder">
          </mat-form-field>
          &nbsp;
          <mat-form-field appearance="outline">
            <mat-label>Confirm Password</mat-label>
            <input type="password" matInput placeholder="Placeholder">
          </mat-form-field>

        </form>
        <div>
          <button type="submit" class="btn btn-primary login" (click)="btnClick();">Register</button>
        </div>
      </div>
    </div>
  </div>
</div>

Please help me out .Thank You.

I am new to Angular development, trying to create a registration form where I need to have two columns in a row , like Firstname ,Lastname in one row followed by Phone,Email and Password,Confirm password.I am using mat-form-field, but when I add a new field all are placed next to each other as shown in below picture, I want them in next line.

current form image

ponent.html

<div class="container">
  <div class="row">
    <div class="registration-form col-md-6" style="max-width: -webkit-fill-available;">
      <div class="main-div" style="width: inherit;text-align: center">
        <div class="panel">
          <h2> Registration Form</h2>
        </div>
        <div class="alert alert-danger" *ngIf="errorMsg">
          {{errorMsg}}
        </div>
        <form #registartionForm="ngForm" (ngSubmit)="onSubmit()" novalidate>
          <mat-form-field appearance="outline">
            <mat-label>First Name</mat-label>
            <input matInput placeholder="Placeholder">
          </mat-form-field>
          &nbsp;
          <mat-form-field appearance="outline">
            <mat-label>Last Name</mat-label>
            <input matInput placeholder="Placeholder">
          </mat-form-field>
          &nbsp;
          <mat-form-field appearance="outline">
            <mat-label>Email</mat-label>
            <input matInput placeholder="Placeholder">
          </mat-form-field>
          &nbsp;
          <mat-form-field appearance="outline">
            <mat-label>Phone Number</mat-label>
            <input matInput placeholder="Placeholder">
          </mat-form-field>
          &nbsp;
          <mat-form-field appearance="outline">
            <mat-label>Password</mat-label>
            <input type="password" matInput placeholder="Placeholder">
          </mat-form-field>
          &nbsp;
          <mat-form-field appearance="outline">
            <mat-label>Confirm Password</mat-label>
            <input type="password" matInput placeholder="Placeholder">
          </mat-form-field>

        </form>
        <div>
          <button type="submit" class="btn btn-primary login" (click)="btnClick();">Register</button>
        </div>
      </div>
    </div>
  </div>
</div>

Please help me out .Thank You.

Share Improve this question edited Jun 4, 2021 at 2:42 Akber Iqbal 15k12 gold badges53 silver badges75 bronze badges asked Dec 12, 2018 at 4:19 BKKBKK 5032 gold badges5 silver badges18 bronze badges 1
  • 1 group your elements in div which you want them in single row – super cool Commented Dec 12, 2018 at 4:23
Add a ment  | 

2 Answers 2

Reset to default 8

while continuing to use Angular Material, you can set a div around each pair to get what you want... working example @ https://stackblitz./edit/angular-qqrwni

<form #registartionForm="ngForm" (ngSubmit)="onSubmit()" novalidate >

          <div >
            <mat-form-field appearance="outline">
              <mat-label>First Name</mat-label>
              <input matInput placeholder="First Name">
            </mat-form-field>
            &nbsp;
            <mat-form-field appearance="outline">
              <mat-label>Last Name</mat-label>
              <input matInput placeholder="Last Name">
            </mat-form-field>
            &nbsp;
          </div>
          <div >
            <mat-form-field appearance="outline">
              <mat-label>Email</mat-label>
              <input matInput placeholder="Email">
            </mat-form-field>
            &nbsp;
            <mat-form-field appearance="outline">
              <mat-label>Phone Number</mat-label>
              <input matInput placeholder="Phone Number">
            </mat-form-field>
            &nbsp;
          </div>
          <div >
            <mat-form-field appearance="outline">
              <mat-label>Password</mat-label>
              <input type="password" matInput placeholder="Password">
            </mat-form-field>
            &nbsp;
            <mat-form-field appearance="outline">
              <mat-label>Confirm Password</mat-label>
              <input type="password" matInput placeholder="Confirm Password">
            </mat-form-field>
          </div>
        </form>

Its better to use bootstrap and paste this code in your html file.

 <div class="container">
  <h1>Register</h1>
  <p>Please fill in this form to create an account.</p>
  <hr>
  <label for="email"><b>Email</b></label>
  <input type="text" placeholder="Enter Email" name="email" required>
  <label for="psw"><b>Password</b></label>
  <input type="password" placeholder="Enter Password" name="psw" required>
  <label for="psw-repeat"><b>Repeat Password</b></label>
  <input type="password" placeholder="Repeat Password" name="psw-repeat" required>
  <button type="submit" class="registerbtn">Register</button>
 </div>
发布评论

评论列表(0)

  1. 暂无评论