在AngularJS中单独处理相同的div

时间:2017-03-20 18:52:31

标签: javascript angularjs

var app = angular.module('app', []);

app.controller("MyController", ['$scope', function($scope) {
  $scope.comments = [
  ];  
    $scope.createComment = function() {

      $scope.comments.push({
        comment: $scope.newComment.comment,
      });
    
  };
}]);  
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="container" ng-app="app" ng-controller="MyController">
  <div ng-repeat="comment in comments">
    <div class="comment_user">
      <span>{{comment.comment}}</span>
    </div>
  </div>
  <div class="add_com_to_qu05">
    <a ng-click="showDetailsAnswer = ! showDetailsAnswer">Add Comment</a>
  </div>
   <div class="area_comm_tex" ng-show="showDetailsAnswer">
    <textarea class="text_area" ng-model="newComment.comment" placeholder="Add comment..."></textarea>
    <button ng-click="createComment()" class="op_comm_now">send text</button>
  </div>
  <div ng-repeat="comment in comments">
    <div class="comment_user">
      <span>{{comment.comment}}</span>
    </div>
  </div>
  <div class="add_com_to_qu05">
    <a ng-click="showDetailsAnswer = ! showDetailsAnswer">Add Comment</a>
  </div>
   <div class="area_comm_tex" ng-show="showDetailsAnswer">
    <textarea class="text_area" ng-model="newComment.comment" placeholder="Add comment..."></textarea>
    <button ng-click="createComment()" class="op_comm_now">send text</button>
  </div>
</div>

嘿,我是AngularJS的新手这个例子在纯JS中很简单,但我不知道在AngularJS中。我在JS中有两个相同的部分Add comment可以使用$this来分隔这些Add comment

问题:如何在Agular中检测单击的div。如何在此示例中添加单个注释

0 个答案:

没有答案