【问题标题】:Swap Follow/Following button based on whether or not the user Follows the individual根据用户是否关注个人交换关注/关注按钮
【发布时间】:2017-07-22 15:51:31
【问题描述】:

我正在尝试根据当前用户是否关注其他人来交换关注/关注按钮。在我的代码中,我设置了 NgIF,我遇到的困难是检查数组中的值。如果代码中只有一个用户名适用于该用户。但是,如果数组有多个索引,则代码会将值变为 false。

HTML:

<div *ngFor="let pic of pics">
  <span *ngIf="pic.user!=current">
      <span *ngIf="pic.user!=cFollows"> 
        <button ion-button>Follow</button>
      </span>
      <span *ngIf="pic.user==cFollows">
        <button ion-button>Following</button>
    </span>

我的 TS 文件(图片中的所有数据都是 JSON 格式:

pics = []
cFollows = ["user1","user2"]

所以基本上如果 pic.user 的字符串值等于数组中的任何字符串,则显示以下按钮。如果没有显示关注按钮。

【问题讨论】:

    标签: html angularjs typescript parse-platform ionic2


    【解决方案1】:

    所以我发现我需要更改代码以匹配下面

      <span *ngIf="pic.user!=current">
         <span *ngIf="cFollows.indexOf(pic.user)==-1"> 
            <button ion-button>Follow</button>
          </span>
          <span *ngIf="cFollows.indexOf(pic.user)!=-1">
            <button ion-button>Following</button>
          </span>
      </span>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-12
      • 1970-01-01
      • 1970-01-01
      • 2017-12-24
      • 1970-01-01
      • 1970-01-01
      • 2013-01-25
      相关资源
      最近更新 更多