如何基于布尔值在 AngularJS 中切换 ng-show? [英] How do I toggle an ng-show in AngularJS based on a boolean?

查看:22
本文介绍了如何基于布尔值在 AngularJS 中切换 ng-show?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于回复消息的表单,仅当 isReplyFormOpen 为 true 时才显示,并且每次单击回复按钮时,我都想切换是否显示该表单.我该怎么做?

解决方案

你只需要在 ng-click 事件上切换 "isReplyFormOpen" 的值

回复<div ng-show="isReplyFormOpen" id="replyForm">

I have a form for replying to messages that I want to show only when isReplyFormOpen is true, and everytime I click the reply button I want to toggle whether the form is shown or not. How can I do this?

解决方案

You just need to toggle the value of "isReplyFormOpen" on ng-click event

<a ng-click="isReplyFormOpen = !isReplyFormOpen">Reply</a>
 <div ng-show="isReplyFormOpen" id="replyForm">
   </div>

这篇关于如何基于布尔值在 AngularJS 中切换 ng-show?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆