Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度:如何更新递归指令范围/模型_Javascript_Angularjs_Directive - Fatal编程技术网

Javascript 角度:如何更新递归指令范围/模型

Javascript 角度:如何更新递归指令范围/模型,javascript,angularjs,directive,Javascript,Angularjs,Directive,我使用递归指令呈现嵌套注释树。基本上,父注释可以有子注释,每个子注释可以有自己的子注释 每个评论也有一个回复字段,并向我的后端API发出post请求 我的指令代码: commentTree.directive("tree", function($compile) { return { restrict: "E", scope: {parent: '=', onReply: '&'}, template: '<ul>' +

我使用递归指令呈现嵌套注释树。基本上,父注释可以有子注释,每个子注释可以有自己的子注释

每个评论也有一个回复字段,并向我的后端API发出post请求

我的指令代码:

commentTree.directive("tree", function($compile) {
  return {
    restrict: "E",
    scope: {parent: '=', onReply: '&'},
    template:
      '<ul>' +
          '<li ng-repeat="comment in parent">' +
              '<p>{{ comment.body }}</p>' +
              '<label>by {{ comment.submitter }}</label><label>@ {{ comment.created_at | date : "MM/dd @ h:mma" }}</label>' +
              '<form>' +
                '<label>Comment: </label><textarea ng-model="commentBody"></textarea>' +
                '<button ng-click="onReply({comment : comment, commentBody: commentBody})" class="btn btn-default">Reply</button>' +
              '</form>' +
              '<tree parent="comment.comments" on-reply="onReply({comment : comment, commentBody: commentBody})"></tree>' +
          '</li>' +
      '</ul>',
    compile: function(tElement, tAttr, transclude) {
      var contents = tElement.contents().remove();
      var compiledContents;
      return function(scope, iElement, iAttr) {
        if(!compiledContents) {
            compiledContents = $compile(contents, transclude);
        }
        compiledContents(scope, function(clone, scope) {
                 iElement.append(clone);
        });
      };
    }
  };
});
我猜这不起作用,因为指令不知道如何连接它?不太确定,如果有任何提示,我们将不胜感激

澄清一下:我用HTML调用我的指令,如下所示:

$http.post("/api/comments", { comment: { body: comment , story_id: $routeParams.id }}).
      success(function(createdComment) {
        $scope.allComments.push(createdComment);
      }
    )