Button按钮

点击后会触发一个操作。

代码演示

基本用法

最简单的用法。

  1. import { Component } from '@angular/core';
  2. @Component({
  3. selector: 'demo-button-basic',
  4. template: `
  5. <WingBlank>
  6. <div Button [type]="'dashed'" (onClick)="onClick()">dashed</div>
  7. <WhiteSpace></WhiteSpace>
  8. <div Button (onClick)="onClick()">default</div>
  9. <WhiteSpace></WhiteSpace>
  10. <div Button [disabled]="true">default diasbled</div>
  11. <WhiteSpace></WhiteSpace>
  12. <div Button [type]="'primary'">primary</div>
  13. <WhiteSpace></WhiteSpace>
  14. <div Button [type]="'primary'" [disabled]="true">primary diasbled</div>
  15. <WhiteSpace></WhiteSpace>
  16. <div Button [type]="'warning'">warning</div>
  17. <WhiteSpace></WhiteSpace>
  18. <div Button [type]="'warning'" [disabled]="true">warning</div>
  19. <WhiteSpace></WhiteSpace>
  20. <div Button [loading]="true">loading</div>
  21. <WhiteSpace></WhiteSpace>
  22. <div Button [icon]="'check-circle-o'">with icon</div>
  23. <WhiteSpace></WhiteSpace>
  24. <div Button [icon]="img">
  25. with custom icon
  26. </div>
  27. <ng-template #img>
  28. <img src="https://gw.alipayobjects.com/zos/rmsportal/jBfVSpDwPbitsABtDDlB.svg" alt="" />
  29. </ng-template>
  30. <WhiteSpace></WhiteSpace>
  31. <div Button style="margin-right: 4px" [type]="'primary'" [inline]="true">inline primary</div>
  32. <div Button [type]="'ghost'" [inline]="true">inline ghost</div>
  33. <WhiteSpace></WhiteSpace>
  34. <div Button style="margin-right: 4px" [type]="'primary'" [inline]="true" [size]="'small'">primary</div>
  35. <div Button [type]="'primary'" [inline]="true" [disabled]="true" [size]="'small'">primary diasbled</div>
  36. <WhiteSpace></WhiteSpace>
  37. <div Button style="margin-right: 4px" [type]="'ghost'" [inline]="true" [size]="'small'">ghost</div>
  38. <div Button [type]="'ghost'" [inline]="true" [disabled]="true" [size]="'small'">ghost diasbled</div>
  39. </WingBlank>
  40. <List className="my-list">
  41. <ListItem [extra]="ghost" [arrow]="'horizontal'">
  42. Regional manager
  43. <Brief>Can be collected, refund, discount management, view data and other operations</Brief>
  44. </ListItem>
  45. <ListItem [extra]="primary" [arrow]="'horizontal'">
  46. Regional manager
  47. <Brief>Can be collected, refund, discount management, view data and other operations</Brief>
  48. </ListItem>
  49. </List>
  50. <ng-template #ghost>
  51. <div Button [type]="'ghost'" [inline]="true" style="margin-right: 4px" [size]="'small'">small</div>
  52. </ng-template>
  53. <ng-template #primary>
  54. <div Button [type]="'primary'" [inline]="true" style="margin-right: 4px" [size]="'small'">small</div>
  55. </ng-template>
  56. `
  57. })
  58. export class DemoButtonBasicComponent {
  59. onClick() {
  60. console.log('click');
  61. }
  62. }

Button按钮 - 图1

API

参数说明类型默认值
[type]按钮类型‘default’ | ‘primary’ | ‘ghost’ | ‘warning’‘default’
[size]按钮大小‘large’ | ‘small’large
[disabled]设置禁用booleanfalse
[style]自定义样式object-
[inline]是否设置为行内按钮booleanfalse
[loading]设置按钮载入状态booleanfalse
[icon]可以是 Icon 组件里内置的某个 icon 的 type 值,也可以是任意合法的 TemplateRef (注意: loading设置后此项设置失效)string | TemplateRef-
(onClick)点击按钮的点击回调函数EventEmitter<void>-