angularjs - Reply Textarea for particular post(using textarea), opening for all the comments -
hi trying implement facebook kind of post , reply comments using angularjs. below code
<doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script> </head> <body ng-app="myapp" ng-controller="homectrl"> <div class="container" style="margin-top:1%;"> <div class="row"> <textarea style="width:500px" ng-model="txt" placeholder="add comment..."></textarea></br></br> <button type="button" class="btn btn-default" ng-click="postdata(txt)" ng-model="btn">post</button> </div> </div> <div class="container" style="margin-top:1%;"> <div class="row"> <div ng-show="comment" ng-repeat="data in datas track $index"> {{data}} <div> <a href="#">like</a> <a href="#" ng-click="showinnercomment($index)">comment</a> <a href="#">share</a> </div> <div ng-show="innercomment"> <textarea style="width:500px; height:30px;" ng-model="txt1"></textarea></br></br> <button type="button" class="btn btn-default" ng-click="postreplied(txt1)" ng-model="btn" ng-show="postrepbtn">reply</button> <div ng-show="innercmt" ng-repeat="data1 in innerdata"> {{data1}} </div> </div> </div> </div> </div> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script> <script> var app=angular.module('myapp', []); app.controller('homectrl', ['$scope', function($scope) { $scope.comment=false; $scope.innercomment=false; $scope.datas=[]; $scope.innerdata=[]; $scope.innercmt=false; $scope.postrepbtn=true; $scope.postdata=function(txt) { $scope.comment=true; $scope.datas.push(txt); $scope.txt=''; } $scope.showinnercomment=function($index) { console.log($index) $scope.innercomment=true; } $scope.postreplied=function(txt1) { $scope.innerdata.push(txt1); $scope.innercmt=true; //$scope.postrepbtn=false; $scope.txt1=''; } }]); </script> </body> </html> now problem facing (assuming have posted 3 comments), not able open reply(textarea) particular comment(link), instead opening textarea(reply) comments when clicking on comment link. not able solve issue.or there other way solve it?? appreciated.
thanks
i attching images 

make $scope.innercomment array of booleans.
$scope.innercomment = []; now modify in view ng-show="innercomment[$index]"
this way can set value true particular comment.
$scope.showinnercomment=function($index) { console.log($index) $scope.innercomment[$index]=true; } note: whenever add comment , push false in innercomment.
Comments
Post a Comment