子元素未显示在ng-include

时间:2015-06-07 15:40:43

标签: angularjs

我创建了一个内联指令来显示来自Java脚本数组的注释。 comments数组的结构如下

$scope.comments = [{
                userName:   'TestUser', 
                comment :   'Parent Comment',           
                comments: [ ] //Holds the Replies
                }];

我正在以编程方式在 $ scope.comments 数组中添加对 comments 数组的回复。

Inline Directive片段如下

  <div>
  <script type="text/ng-template" id="categoryTree">
  <div class="media-body">                          
            <h4>{{ comment.userName }} </h4>
            <p> {{ comment.comment }} </p>
    </div>

    <ul ng-if="comment.comments">
      <li ng-repeat="comment in comment.comments" ng-include="'categoryTree'">
      </li>
    </ul>
  </script>

  <ul>
    <li ng-repeat="comment in comments" ng-include="'categoryTree'"></li>
  </ul> 
  </div>

当我将父评论添加到 $ scope.comments 时,会显示它们。但是,当我在 $ scope.comments 数组中添加对评论数组的回复时,它不会显示。

此外,如果我使用 angular.element(document).ready 中的所有评论和回复初始化 $ scope.comments ,则会显示正确< /强>

请让我知道我哪里出错了以及如何解决。

其他信息 当我在独立页面中使用指令时,所有这一切都正常工作,但当我在“ng-view”中使用此内容时开始出现问题

1 个答案:

答案 0 :(得分:0)

此行为被视为一个错误,已在AngularJS的更高版本中修复。上面的示例适用于AngularJS 1.4.0版