ngx-quill无法显示下拉标签

时间:2018-10-19 07:29:42

标签: angular quill ngx-quill

我在鹅毛笔中创建了一个自定义下拉菜单。我用羊皮纸

var Parchment = Quill.import('parchment');
    var lineHeightConfig = {
      scope: Parchment.Scope.INLINE,
      whitelist: [
        '1.0',
        '5.0',
        '10.0'
      ]
    };
    var lineHeightClass = new Parchment.Attributor.Class('lineheight', 'ql-line-height', lineHeightConfig);
    var lineHeightStyle = new Parchment.Attributor.Style('lineheight', 'line-height', lineHeightConfig);
    Parchment.register(lineHeightClass);
    Parchment.register(lineHeightStyle);

我在视图中定义了编辑器:

<quill-editor #editor >
<div quill-editor-toolbar>
          <!-- Basic buttons -->
          <span class="ql-formats">
            <button class="ql-bold" [title]="'Bold'"></button>
            <button class="ql-italic" [title]="'Italic'"></button>
            <button class="ql-underline" [title]="'Underline'"></button>
          </span>

          <span class="ql-formats">
            <select class="ql-lineheight" [title]="'Line Height'">
              <option selected></option>
              <option value="1.0"></option>
              <option value="5.0"></option>
              <option value="10.0"></option>
            </select>      
          </span>          
    </div>

</quill-editor>

然后添加一些CSS定义:

.ql-snow .ql-picker.ql-lineheight{
  width: 58px;

}

.ql-snow .ql-picker.ql-lineheight .ql-picker-item[data-value="1.0"]::before {content: "1.0";}
.ql-snow .ql-picker.ql-lineheight .ql-picker-label[data-value='1.0']::before {content: '1.0' !important;}

.ql-snow .ql-picker.ql-lineheight .ql-picker-item[data-value='5.0']::before {content: '5.0';}
.ql-snow .ql-picker.ql-lineheight .ql-picker-label[data-value='5.0']::before {content: '5.0' !important;}

.ql-snow .ql-picker.ql-lineheight .ql-picker-item[data-value='10.0']::before {content: '10.0';}
.ql-snow .ql-picker.ql-lineheight .ql-picker-label[data-value='10.0']::before {content: '10.0' !important;}

新的下拉列表显示并可以使用,但标签仍然为空。

这里有一个stackblitz

1 个答案:

答案 0 :(得分:1)

不是很确定这是执行此操作的正确方法...我使用AfterViewInit

  ngAfterViewInit() {
    var lineheightToolbarButton = document.querySelector('.ql-lineheight');
    var lineheightButtonLabel = document.getElementsByClassName('ql-picker-label')[0]
    lineheightButtonLabel.innerHTML = "line height"+lineheightButtonLabel.innerHTML
    var lineheightItems = document.getElementsByClassName('ql-picker-item')

    for (var i = 0; i < lineheightItems.length; i++) {
       lineheightItems[i].innerHTML = lineheightItems[i].getAttribute('data-value')
    }
  }