javascript - 如何使图标与 Angular 5/6 中的按钮类似?

标签 javascript angular typescript angular-material2

我正在编写一个代码来编辑帐户信息中的名称,并且按钮工作正常,但我希望将编辑按钮作为图标(铅笔)。 Icon不支持ngIf,有什么替代方案吗? ( Angular 5/6)我的代码如下:

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

代码输出:

The Code Output

最佳答案

:) 将其添加到答案中以使其计数!只需在按钮标签内放置一个图标,如下所示:

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

关于javascript - 如何使图标与 Angular 5/6 中的按钮类似?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53938176/

相关文章:

angular - 在 Angular 中操作/引用 DOM 元素的正确方法

javascript - 解析 XML 中的标签

javascript - 在 iphone 上使用 webkit-transform 和相对定位时如何修复慢速滚动

typescript - Angular2 中多个类的 setElementClass

javascript - 根据 Angular 2 中的数据库值动态加载数据卡

angular - 使用 Protractor typescript ,我如何检测这个元素方形白框,然后单击并拖动白框,它有 ng-mousedown 和转换

javascript - typescript 模块没有导出成员 - react

typescript - 如何在 typescript 中使用原型(prototype)

javascript - 浏览器如何区分两个相同的 HTML 元素?

javascript - (jQuery) 选择 document.body 而不是父元素