ionic4 ion-select 去掉默认的箭头

  ionViewDidEnter() {
    let select_elements = (this.el.nativeElement.querySelectorAll('ion-select'));
    const styles = `
      .select-icon, .select-icon-inner {
        display: none;
      }
      .select-placeholder {
        color: #bfbfbf;
      }
    `;
    select_elements.forEach((element) => {
      this.injectStyles(element, '.select-icon', styles);
    });
  }
  injectStyles(
    shadowRootElement: HTMLElement,
    insertBeforeSelector: string,
    styles: string
  ) {
    const root = shadowRootElement.shadowRoot;
    const newStyleTag = document.createElement('style');
    newStyleTag.innerHTML = styles;
    root.insertBefore(newStyleTag, root.querySelector(insertBeforeSelector));
  }
github上有个injectStyles库函数,但是实现有问题,我看了一下它的源码,自己实现了一下,就是上面这个injectStyles()。

posted @ 2019-11-25 14:53  johnjackson  阅读(1370)  评论(0编辑  收藏  举报