简体   繁体   中英

Angular Material spinner inline with input field

I am generating a bunch of buttons under an input field that counts down to 0 when a correct number is entered. I'd like to add a progress spinner right next to (horizontally next to) the "ns left" display. I currently have:

  <mat-card class="card mat-elevation-z5">
      <mat-form-field>
        <mat-label>Username</mat-label>
        <input id="nameInput" matInput>
        <p matSuffix>{{timeLeft}}s left</p>
        <mat-spinner [diameter]="40"></mat-spinner>
      </mat-form-field>  
     <mat-button-toggle 
        *ngFor="let button of buttonsFromApi" 
        id="{{button.id}}">
        {{button.displayName}}
      </mat-button-toggle>
</mat-card>

My problem is, no matter how I try, the spinner ends up under the text, never next to it. I've tried a combination of flexboxes, additional divs, different layouts, and it never worked... How could I make sure that the inputfield is centered and in line with all the buttons (in a column) while having a spinner right next to the countdown? Eg I have:

在此处输入图片说明

and I want:

在此处输入图片说明

CSS:

.card {
    min-width: 50%;
    display: flex;  
    flex-flow: column wrap;
  }
mat-form-field {
    font-size: 2em;   
    min-width: 50%;
}

You can try something like this:

<p matSuffix style="display: inline;">{{timeLeft}}s left</p>
<mat-spinner matSuffix [diameter]="18" style="float: right; margin-left: 8px"></mat-spinner>

You can also replace the <p> tag by a <span> that is inline by default.

Thanks Md. Rafee for the live example: stackblitz

<mat-form-field>您可以将matSuffix与微调器一起使用,只需添加一些带有display: inline-flex样式,您就可以开始了:

<mat-spinner *ngIf="form.pending" matSuffix diameter="16" style="display: inline-flex"></mat-spinner>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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