0

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.

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

Here is plukr link

2
  • 1
    Your mistake here is you are binding the same object (_reply) to all the instance of the comment sections. instead try different object with each one then try it out. Commented Aug 1, 2016 at 12:04
  • Yes, as @JenishRabadiya said, you are using same object '_reply' for every ng-if, either create an array of objects or create different object every time. Commented Aug 1, 2016 at 12:31

1 Answer 1

1

You should assign replyActive bit for each comment. To do that, you can use iteration objects (I assumed you are using 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. Check this fiddle, http://jsfiddle.net/Lvc0u55v/7762/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.