2

I'm using Angular 7. When I open my dialog, I want to set a star icon after the input, as shown by the arrows, not in the input as at present.

This is my dialog:

enter image description here

This is my html:

<h1 mat-dialog-title>{{'DNS.Create entry' | translate }}</h1>
<div mat-dialog-content fxLayout="row" fxLayoutAlign="center center">
    <form name="createEntryForm" [formGroup]="createEntryForm" fxLayout="column" fxFlex="100">
        <mat-form-field>
            <mat-label>Type</mat-label>
            <mat-select placeholder="type" formControlName="type" [(ngModel)]="entrType">
                <mat-option value="A">A</mat-option>
                <mat-option value="CNAME">CNAME</mat-option>
            </mat-select>
        </mat-form-field>
        <mat-icon class="amber-600-fg" matTooltip="Click to add/remove shortcut">star</mat-icon>
        <mat-form-field *ngIf="entrType == 'A'">
            <mat-label>Hostname</mat-label>
            <input matInput formControlName="hostname">
            <span matSuffix>.{{ domain.name }}</span>
            <mat-error *ngIf="hostname.errors?.pattern">{{'DNS.Hostname not valid' | translate }}</mat-error>
        </mat-form-field>
        <mat-form-field *ngIf="entrType == 'CNAME'">
            <mat-label>Hostname</mat-label>
            <input matInput formControlName="hostname">
            <span matSuffix>.{{ domain.name }}</span>
            <mat-error *ngIf="hostname.errors?.pattern">{{'DNS.Hostname not valid' | translate }}</mat-error>
        </mat-form-field>
        <mat-icon class="amber-600-fg" matTooltip="Click to add/remove shortcut">star</mat-icon>
        <mat-form-field *ngIf="entrType == 'A'">
            <mat-label>{{'DNS.IP address' | translate }}</mat-label>
            <input matInput formControlName="value">
            <mat-error *ngIf="value.errors?.pattern">
                {{'DNS.Value not valid' | translate }}
            </mat-error>
        </mat-form-field>
        <mat-icon class="amber-600-fg" matTooltip="Click to add/remove shortcut">star</mat-icon>
        <mat-form-field *ngIf="entrType == 'CNAME'">
            <mat-label>FQDN cible</mat-label>
            <input matInput formControlName="value">
            <mat-error *ngIf="value.errors?.pattern">
                {{'DNS.Value not valid' | translate }}
            </mat-error>
        </mat-form-field>
        <mat-form-field>
            <mat-label>TTL</mat-label>
            <mat-select placeholder="ttl" formControlName="ttl" [(ngModel)]="ttlType">
                <mat-option value="300">5 min</mat-option>
                <mat-option value="3600">{{'DNS.1 hour' | translate }}</mat-option>
                <mat-option value="86400">{{'DNS.1 day' | translate }}</mat-option>
            </mat-select>
        </mat-form-field>
        <mat-icon class="amber-600-fg" matTooltip="Click to add/remove shortcut">star</mat-icon>
    </form>
</div>
<div mat-dialog-actions fxLayoutAlign="end center">
    <button mat-button (click)="onCancelClick()">{{'DNS.Cancel' | translate }}</button>
    <button mat-raised-button color="primary" [mat-dialog-close]="createEntryForm" [disabled]="createEntryForm.invalid">{{'DNS.Create'
        | translate }}</button>
</div>

I appreciate any help to resolve this problem.

3
  • Do you give the wrapping div enough width ? Commented Mar 27, 2019 at 15:12
  • I did not understand what you mean ?? Commented Mar 27, 2019 at 15:13
  • I meant the form need to be wider. You can style it in css or flexlayout I guess. There a is an overflow. Something like fxFlex="120" ? Commented Mar 27, 2019 at 15:15

3 Answers 3

1

Use matPrefix or matSuffix

<mat-form-field>
    <input matInput placeholder="Amount" type="number">
    <span matPrefix>ICON HERE</span>
    <span matSuffix>ICON HERE</span>
</mat-form-field>

https://stackblitz.com/angular/vkgoyrdlnyjp?file=app%2Fform-field-prefix-suffix-example.html

https://material.angular.io/components/form-field/overview

Sign up to request clarification or add additional context in comments.

1 Comment

I want to insert after the input not in the input
1

To keep the image out of the actual input, but on the same row, you can put the input and the image in a row of their own:

<div fxLayout="row"> 
<mat-form-field>
        <mat-label>Type</mat-label>
        <mat-select placeholder="type" formControlName="type" [(ngModel)]="entrType">
            <mat-option value="A">A</mat-option>
            <mat-option value="CNAME">CNAME</mat-option>
        </mat-select>
</mat-form-field>
<mat-icon class="amber-600-fg" matTooltip="Click to add/remove shortcut">star</mat-icon>
</div>

Comments

0

use font awesome for you input fields

mat-selec::after { 
  font-family: "Font Awesome 5 Free";
  content: "\f005";
}

2 Comments

i try what you gave me but he inserts the icon in the input me i want to insert it after the input show the image please
use font awesome for you input fields

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.