在ng-repeat中成功执行ajax请求后再次调用函数

时间:2015-09-27 21:37:11

标签: ajax angularjs

我有这样的功能:

scope.addReply = function(el) {

  createCommentFactory.saveComment(scope.form.reply[el.pivot.comment_id], el.pivot.project_id, el.pivot.comment_id, el.level + 1)
    .success(function(data) {

      //ADD REPLY TO CLIENT SIDE
      scope.comments.splice(scope.comments.indexOf(el) + 1, 0, data);

      //TOGGLE FORM AFTER SUCCESSFUL AJAX REQ
      el.formWhat = !el.formWhat;
    })
    .error(function(data) {
      console.log(data);
    });

  // RESET REPLY TEXT AREA
  scope.form.reply = "";
};

HTML:

<div dir-paginate="x in comments | itemsPerPage: commentsPerPage">
  <form ng-submit="addReply(x)" class="dd animated slideInDown" novalidate>
    <ng-form name="replyForm">
      <div class="form-group">
        <text-angular name="replyText<%x.pivot.comment_id%>" ta-default-wrap="span" ta-max-text="600" ta-min-text="15" ta-text-editor-class="form-control myform1-height" ta-html-editor-class="form-control myform1-height" ta-toolbar="[['bold','italics']]" style="min-height: 100px; color:red;" 
                      ng-model="form.reply[x.pivot.comment_id]" required></text-angular>

        <p style="color:red" ng-show="replyForm.replyText<%x.pivot.comment_id %>.$error.taMaxText">
          Text should not be more then 600 characters.</p>
        <p style="color:red" ng-show="replyForm.replyText<%x.pivot.comment_id %>.$error.taMinText">
          Text should be at last 15 characters.</p>
      </div>
      <div class="form-group">
        <input addreply ng-disabled="replyForm.replyText<%x.pivot.comment_id%>.$invalid" class="btn btn-default pull-right"
               type="submit" value="Send"/>
      </div>
    </ng-form>
  </form>
</div>

函数,在ajax成功之后,会将项目推送到我在里面回复的评论下面:scope.comments ...现在问题是我无法提交我用ajax请求添加的表单,因为表单不是由ng-repeat,for是在ajax请求之后创建的:scope.comments.splice(scope.comments.indexOf(el) + 1, 0, data);

0 个答案:

没有答案