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()。
喜欢的话,请点赞,转发、收藏、评论,谢谢!