angular - 关于 twitter 类型跟随/取消关注 Angular 功能的基本概念?
问题描述
登录任何用户并查看另一个用户名称的列表,并且名称前面有一个按钮关注,单击关注按钮后,它会切换并将名称更改为取消关注后取消关注按钮再次切换并更改关注如何使这种类型的关注取消关注角度的功能?
在数据库中我有用户表,我必须创建新的跟随表(需要哪一列才能做到这一点),跟随需要哪种类型的查询,取消关注需要哪种类型的查询?
解决方案
//here is toggle button code
//twitter-component.html
<style>
.followup{
color: red
}
.unfollow{
color: green
}
</style>
<form>
<button [ngClass]="{'followup' : isFollow == true,
'unfollow' : isFollow== false }"
(click)="onClick()">
{{isFollow == true ? 'Unfollow' : (isFollow == false ? 'Follow' : '')}}
</button>
</form>
//twitter-component.ts
export class TwitterComponent implements OnInit {
public isFollow: boolean = false;
ngOnInit() {
}
onClick(){
this.isFollow = !this.isFollow;
}
}
推荐阅读
- c - 在堆栈中交替显示顶部和底部
- typescript - 打字稿手动缩小子范围内的联合类型
- single-sign-on - Nginx 反向代理后面的 Tomcat - 收件人端点与 SAML 响应不匹配
- c# - Polly 使用 URL、标头、内容和响应记录所有请求
- r-markdown - 如何在 R Markdown 中按降序将表中的值放入表中?
- python - 如何解决“TypeError: cannot unpack non-iterable int object”
- javascript - 如何在样式规范中添加 mapbox api?
- typo3 - 未声明的参数传递给 ViewHelper maxRange
- cmake - Conan.io 和仅标头库
- python - 使用 Python 更快地获取 Windows 文件的所有者