How to make icon work similar to button in angular 5/6?

筅森魡賤 提交于 2019-12-12 01:17:00

问题


I'm writing a code to edit names in account information and button works fine but i want edit button as an icon (pencil). Icon does not support ngIf, is there any alternative? (Angular 5/6) My code is as follows:

<div>
   <mat-form-field class="example-full-width" *ngIf="edit">
    <input matInput placeholder="Enter name . [(ngModel)]="name">
   </mat-form-field>
   <span *ngIf="!edit">Name : {{name}}</span>
</div>
<div class="example-button-row">
   <button mat-raised-button color="primary" *ngIf="!edit" 
    (click)="onEdit()">Edit</button>
   <button *ngIf="edit" mat-raised-button color="primary" 
    (click)="onEdit()">Submit</button> 
</div>

Code Output:


回答1:


:) adding it to the answer to make it count! Just put an icon inside the button tag like this:

<button
    mat-raised-button
    color="primary"
    (click)="onEdit()">
    <span *ngIf="!edit">Edit</span>
    <span *ngIf="edit" > Put your icon here </span> 
</button>



回答2:


As Uma pointed out, you can just put mat-icon inside the button.

Please see code example below: https://stackblitz.com/edit/mat-button-icon-example



来源:https://stackoverflow.com/questions/53938176/how-to-make-icon-work-similar-to-button-in-angular-5-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!