嗨,我正在尝试制作类似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>
答案 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'))