首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用带有按钮的ng-switch

使用带有按钮的ng-switch
EN

Stack Overflow用户
提问于 2017-08-18 15:30:07
回答 3查看 3.2K关注 0票数 2

我正在尝试使用带有两个按钮的ng-switch,以便根据所单击的按钮显示HTML元素。我还没见过这样的例子

到目前为止,我的代码如下:

代码语言:javascript
复制
<button name="withdraw" ng-click="type(name)">Withdraw</button>
<button name="enter" ng-click="type(name)">Enter Amount to Withdraw</button>
<hr>

<div ng-switch="type(name)">
        <div ng-switch-when="withdraw">
            //code
        </div>
        <div ng-switch-when="enter">
            //code
        </div>
</div>
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-08-18 15:44:28

试一下这个:

代码语言:javascript
复制
<button name="withdraw" ng-click="name = 'withdraw'">Withdraw</button>
<button name="enter" ng-click="name = 'enter'">Enter Amount to Withdraw</button>
<hr>

<div ng-switch="name">
        <div ng-switch-when="withdraw">
            code 1
        </div>
        <div ng-switch-when="enter">
            code 2
        </div>
</div>
票数 1
EN

Stack Overflow用户

发布于 2017-08-18 16:19:40

如果您使用的是依赖按钮,请使用单选按钮。

代码语言:javascript
复制
  <input type="radio" ng-model="myVar" value="withdraw">withdraw
  <input type="radio" ng-model="myVar" value="enter"> enter

在条件中使用与的模型值

代码语言:javascript
复制
 <div ng-switch="myVar">
      <div ng-switch-when="withdraw">
         <h1>withdraw</h1>
      </div>
      <div ng-switch-when="enter">
         <h1>enter</h1>
      </div>

</div>
票数 2
EN

Stack Overflow用户

发布于 2020-07-12 20:47:39

这适用于angular类型的脚本:

1.app.cpmponent.html

代码语言:javascript
复制
<div class="wapper">
  <button (click)="toggle()"></button>
  <div class="up" *ngIf="show">
    <label>
      <input type="file" (change)="handleFileImage($event.target.files)" accept=".jpg,.svg,.png,.jpeg " />
      <img width="100%" height="100%" *ngIf="imageUrl" [src]="imageUrl" class="image" />

    </label>
  </div>

  <div class="up" *ngIf="!(show)">
    <label>
      <input type="file" (change)="handleFileVideo($event.target.files)" accept=".mp4" />

      <video autoplay width="100%" height="100%" *ngIf="videoUrl" class="image">
        <source [src]="videoUrl" autoplay>
      </video>
    </label>
  </div>
</div>

2.app.component.ts

代码语言:javascript
复制
export class AppComponent{
  fileToUpload: any;
  imageUrl: any;
  videoUrl: any;
  show = true;

  handleFileImage(file: FileList) {
    this.fileToUpload = file.item(0);

    //Show image preview
    let reader = new FileReader();
    reader.onload = (event: any) => {
      this.imageUrl = event.target.result;
    };
    reader.readAsDataURL(this.fileToUpload);
  }
  handleFileVideo(file: FileList) {
    this.fileToUpload = file.item(0);

    let reader = new FileReader();
    reader.onload = (event: any) => {
      this.videoUrl = event.target.result;
    };
    reader.readAsDataURL(this.fileToUpload);
  }


  toggle() {
    this.show = !this.show;

    if (this.show) {

    } else {
    }
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45750920

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档