gpt4 book ai didi

mysql - 如何使用 Mysql Node.js 在 *ngFor 循环内使用 *ngIf 条件显示默认空值按钮,不喜欢和默认按钮

转载 作者:行者123 更新时间:2023-11-29 16:16:54 25 4
gpt4 key购买 nike

您好,我正在尝试制作像 YouTube 这样的喜欢、不喜欢和默认按钮系统,但是当我使用默认按钮时遇到错误,前两个条件(喜欢、不喜欢)运行良好,但我无法显示默认按钮当MySQL表中没有值时。这里我使用两个表 posts(post_id, user_id, description), 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>

最佳答案

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

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

关于mysql - 如何使用 Mysql Node.js 在 *ngFor 循环内使用 *ngIf 条件显示默认空值按钮,不喜欢和默认按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54709969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com