ng-if 条件无法正常工作 [AngularJS]

ng-if condition not working properly [AngularJS]

当我点击评论或回复时 link 表格会打开所有卡片。如何设置特定范围,以便仅在单击 link 时打开表单。

下面的函数与 html 中的 ng-if 一起使用来隐藏 form.Once 单击它应该只打开相应的表单。

 $scope.increaseReply = function(object) {
   object.replyone += 1;
 };

Here is plukr link

您应该为每个评论分配 replyActive 位。为此,您可以使用迭代对象(我假设您使用的是 ng-repeat)。您可以向您的对象添加一个 属性 交互并自由使用它。

简单的例子;

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>

Whosebug 上的代码片段失败,我不知道为什么。检查此 fiddle、http://jsfiddle.net/Lvc0u55v/7762/