[英]ng-if condition not working properly [AngularJS]
When i click comment or reply link the form is opening up for all the cards. 当我单击评论或回复链接时,表格将打开所有卡片。 How to make to a particular scope such that the form should only open for which the link is clicked.
如何对特定范围进行设置,使得仅应在其中单击链接的情况下打开表单。
The below function is used with ng-if in the html to hide the form.Once clicked it should open only the corresponding form. 下面的函数与html中的ng-if一起使用以隐藏该表单,单击后仅应打开相应的表单。
$scope.increaseReply = function(object) {
object.replyone += 1;
};
You should assign replyActive bit for each comment. 您应该为每个注释分配ReplyActive位。 To do that, you can use iteration objects (I assumed you are using ng-repeat).
为此,您可以使用迭代对象(我假设您正在使用ng-repeat)。 You can add one more property to your object interactively and use it freely.
您可以交互地向对象添加一个属性,然后自由使用它。
Simple example; 简单的例子;
var myApp = angular.module('myApp',[]); function MyCtrl($scope) { $scope.commentList = [ { "author": "Tugca Eker", "comment": "You should check this example..." }, { "author": "Gagan", "comment": "ng-if not working" }, { "author": "Tugca Eker", "comment": "Check it again" } ]; }
ul li{ padding: 5px; border: 1px solid black; }
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-controller="MyCtrl"> <ul> <li ng-repeat="comment in commentList" ng-init="comment.isReplyActive = false;"> <b>{{comment.author}}</b>: {{comment.comment}} <br /> <a ng-click="comment.isReplyActive = !comment.isReplyActive;">Reply Now!</a> <div ng-if="comment.isReplyActive"> <input type="text"> </div> </li> </ul> </div>
Snippet on Stackoverflow fails, I don't know why. Stackoverflow上的代码段失败,我不知道为什么。 Check this fiddle, http://jsfiddle.net/Lvc0u55v/7762/
检查这个小提琴, http://jsfiddle.net/Lvc0u55v/7762/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.