如何使用* ngIf条件显示默认的null值按钮,条件是使用Mysql Node.js在* ngFor循环中显示喜欢,不喜欢和默认按钮

时间:2019-02-15 13:03:08

标签: mysql node.js angular ngfor ngif

嗨,我正在尝试制作类似YouTube的“不喜欢”和默认按钮系统,但是当我使用默认按钮时,我遇到了错误,前两个条件(如“不喜欢”)运行良好,但是我无法显示默认按钮当MySQL表中没有值时。这里我使用两个表帖子(post_id,user_id,描述),likes(like_id,user_id,post_id,like_status)列值。

<div class="container" *ngFor="let post of posts; let i = index">

      <div class="
      row" style="border: 1px solid #e6e6e6;">
        <div class="col-md-12 col-md-offset-0" style=" height: auto; ">
          <h6> {{post.description}} </h6>
        </div>
      </div>
<div class="row">

          <!--like button-->
          <div class="col-md-3">
            <div *ngFor="let like of postLikes; let j = index ">

              <div
                *ngIf="( (postLikes != '') && (like.like_id != null) && (like.like_id != '') && (post.user_id == like.user_id) && (post.post_id == like.post_id) && (like.like_status == 'like'))">
                <button type="button" class="btn btn-success" (click)=likeSubmit(post.user_id,post.post_id)><i
                    class="fa fa-thumbs-up" aria-hidden="true"></i></button>{{like.user_id}},{{like.post_id}}
                {{post.post_id}} {{like.like_id}}
              </div>
              <div
                *ngIf="( (like.like_id) && (like.like_id != null) && (like.like_id != '') && (post.user_id == like.user_id) && (post.post_id == like.post_id) && (like.like_status == 'unlike'))">
                <button type="button" class="btn btn-warning" (click)=likeSubmit(post.user_id,post.post_id)><i
                    class="fa fa-thumbs-up" aria-hidden="true"></i></button>{{like.user_id}},{{like.post_id}}
                {{post.post_id}} {{like.like_id}}
              </div>

              <div
                *ngIf=" (post.user_id !=like.user_id) && (!like.like_id) && (postLikes == '') && (like.like_id == null) && (like.like_id == '')">
                <button type="button" class="btn btn-basic" (click)=likeSubmit(post.user_id,post.post_id)><i
                    class="fa fa-thumbs-up" aria-hidden="true"></i></button>{{like.user_id}},{{like.post_id}}
                {{post.post_id}} {{like.like_id}}
              </div>
  </div> 
</div>

1 个答案:

答案 0 :(得分:0)

为什么不将逻辑移至组件源代码? 应该在组件中创建一个变量,很容易在组件文件中调试。

( (postLikes != '') && (like.like_id != null) && (like.like_id != '') 
&& (post.user_id == like.user_id) 
&& (post.post_id == like.post_id) && (like.like_status == 'like'))