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

jq6vz3qz  于 2022-12-08  发布在  Ionic
关注(0)|答案(1)|浏览(187)

你好我正在寻找一种方式在离子使一个按钮,当我点击它,它会显示两个其他按钮。这就是我需要做的:当我点击按钮Allega普通,这个按钮将打开相机和画廊选择图像.一旦图像被选中将显示另外两个按钮,一个查看图像,一个删除.

jexiocij

jexiocij1#

您可以使用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>

这样,您就可以简单地切换要显示的按钮。

相关问题