如何在quill编辑器中使用ng-repeat

时间:2018-05-22 18:52:21

标签: javascript angularjs quill

您好我正在尝试使用Quill编辑器js并将其与ng repeat一起使用。 (我得到了羽毛笔) 我需要使用ng repeat。

此代码返回错误,如:

quill无效的Quill容器#content245

quill无效的Quill容器#content244

quill无效的Quill容器#content243 ....

我需要你的帮助!



        $http.post("/getwallpost", reqGetPost).then(function(response) {
            var accounts = [];
            $scope.postsProfile = response.data
            
            for (var i = 0; i < response.data.length; ++i) {
                if(response.data[i].type_id == 1) {
                     accounts[i] = new Quill("#content" + response.data[i].id + "", optionwall);
                     accounts[i].setContents(JSON.parse(response.data[i].content))
                     
                }
            }
        });
&#13;
<div ng-repeat="post in postsProfile" >
  <div class='postcontent' id='content{{post.id}}'></div>
</div>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

我会尝试在重复

上添加 $http.post("/getwallpost", reqGetPost).then(function(response) { var accounts = []; $scope.postsProfile = response.data for (var i = 0; i < response.data.length; ++i) { if(response.data[i].type_id == 1) { accounts[i] = new Quill("#content" + response.data[i].id + "", optionwall); accounts[i].setContents(JSON.parse(response.data[i].content)) } } $scope.showRepeat = true; }); <div ng-repeat="post in postsProfile" ng-if="showRepeat"> <div class='postcontent' id='content{{post.id}}'></div> </div>
app.directive("lastRepeat", function(){
    return {
        restrict: "A",
        link: function(scope, el, attrs){
            if(scope.$last){
                var eventId = "LR_";
                eventId += !!attrs.lastRepeat ? attrs.lastRepeat : "last";
                scope.$root.$broadcast(eventId);
            }
        }
    };
}); 

修改

也可能是相反的问题。

在打印最后一次重复时,您还应该尝试调用新的Quill ......

<div ng-repeat="post in postsProfile" ng-if="showRepeat" last-repeat="foo">
  <div class='postcontent' id='content{{post.id}}'></div>
</div>

HTML

 $scope.$root.on("LR_foo", function(){
          var data = angular.copy($scope.postsProfile);
          for (var i = 0; i < data.length; ++i) {
                if(data[i].type_id == 1) {
                     accounts[i] = new Quill("#content" + data[i].id + "", optionwall);
                     accounts[i].setContents(JSON.parse(data[i].content))

                }
            }

 });

 $http.post("/getwallpost", reqGetPost).then(function(response) {
            var accounts = [];
            $scope.postsProfile = response.data


            $scope.showRepeat = true;
    });

并在你的js ......

{{1}}

答案 1 :(得分:0)

我发现其他方法可以做到这一点,因为似乎不可能在羽毛笔上使用ng-repeat(或者我不知道答案) 我使用了Jquery追加函数。 但是你必须使用angularJS编译器($ compile)来编译html

您可以查看更多相关信息: append a html include ng-click in angularjs

它简单而且完美无缺