【问题标题】:Binding not working when I use Angular-trix in a modal当我在模态中使用 Angular-trix 时绑定不起作用
【发布时间】:2016-05-29 16:30:07
【问题描述】:

我正在使用 angular-trix。 我启动了一个模式(引导程序),但绑定不起作用。

如果我将绑定放在一个 div 中,我可以看到它被传递到模态但是对于 angular-trix 组件它没有出现。

我的代码是:

         $scope.editCommentDialog = function (comment) {
            var modalInstance = $modal.open({
                templateUrl: 'editCommentDialog.html',
                windowClass : 'edit-comment-modal-dialog',
                controller: function ($scope, $modalInstance, editedComment) {
                    $scope.editedComment = editedComment;

                    $scope.ok = function () {
                        $modalInstance.close(editedComment);
                    };

                    $scope.cancel = function () {
                        $modalInstance.dismiss('cancel');
                    };
                },
                resolve: {
                    editedComment: function () {
                       return { id : comment.id,  text : comment.text};
                    }
                }
            });

            modalInstance.result.then(function (editedComment) {
                $scope.editedComment = editedComment;
                $scope.updateComment();
            }, function () {
                $log.info('Modal dismissed at: ' + new Date());
            });
        };

<script type="text/ng-template" id="editCommentDialog.html">
<div class="modal-header">
    <h3>Edit</h3>
</div>
<div class="modal-body">
    <trix-editor angular-trix ng-model="editedComment.text" class="trix-content editable-trix-editor"></trix-editor>
   </div>
   <div class="modal-footer">
    <button class="btn btn-primary" ng-click="ok()">OK</button>
    <button class="btn btn-warning" ng-click="cancel()">Cancel</button>
</div>
</script>

【问题讨论】:

  • 如果从 .then 回调中删除 $scope.editedComment = editedComment; 会发生什么?
  • 我删除了它,仍然没有绑定。
  • 有人有运气吗?

标签: angularjs twitter-bootstrap


【解决方案1】:
<trix-editor angular-trix ng-model="editedComment.text" class="trix-content editable-trix-editor"></trix-editor>

在您的代码中添加 ng-if="true" 以便它现在看起来:

<trix-editor ng-if="true" angular-trix ng-model="editedComment.text" class="trix-content editable-trix-editor"></trix-editor>

它解决了问题

【讨论】:

    猜你喜欢
    • 2017-05-10
    • 2021-09-18
    • 1970-01-01
    • 1970-01-01
    • 2014-06-24
    • 2016-12-06
    • 1970-01-01
    • 2017-07-30
    • 2016-07-19
    相关资源
    最近更新 更多