离子在一个按钮内创建两个按钮

时间:2018-10-16 13:45:26

标签: javascript angular ionic-framework

你好,我正在Ionic中寻找一种制作按钮的方法,当我单击它时,它将显示另外两个按钮。这就是我需要做的: 当我单击通用按钮Allega时,此按钮将打开“相机”和“图库”以选择图像。选择图像后,将显示另外两个按钮,一个用于查看图像,一个用于删除。

1 个答案:

答案 0 :(得分:1)

如果单击ngIf/else,则可以使用Allega verbale显示按钮。在您的.ts文件中,您将:

export class YourPage {
  // just an property to control whose button is shown
  public allegaClicked: boolean = false;
}

然后在您的HTML中

<ion-content>
  <!-- your content -->
  ...
  <!-- use and ngIf to show your button, when clicked it'll set allegaClicked to the oposite value and show cameraButtons block -->
  <button ion-button (click)="allegaClicked = !allegaClicked" *ngIf="!allegaClicked; else cameraButtons">Allega Verbale</button>
  <!-- when ngIf is false it'll show that block, the else statement only works with ng-template, if you want another element instead of using an ng-template you can use *ngIf="allegaClicked", it's up to you -->
  <ng-template #cameraButtons>
    <div>
      <button ion-button>Camera</button>
      <button ion-button>Gallery</button>
    </div>
  </ng-template>
</ion-content>

这样,您可以简单地切换要显示的按钮。希望这会有所帮助。