如何在mat-select-panel上设置使用打字稿动态计算的最小宽度?

时间:2019-06-13 18:50:07

标签: angular angular-material material-design angular-material2 material

我正在尝试使用mat-select-panel上的自定义打字稿计算设置最小宽度。作为在运行时添加材料的叠加代码,它不是使用renderer2或纯JavaScript添加我计算的最小宽度。基本上,我想将mat-select-panel的宽度设置为与mat-form-field宽度相同。如果我添加一些延迟,则它会设置我的最小宽度,但UI会变差。

我已经尝试过openedChange()的mat-select事件。我在openChange()方法中使用renderer2 setStyle方法编写了自定义宽度计算代码,但未应用。材质会覆盖我的最小宽度。

openedChange(){
 const element = document.getElementsByClassName('mat-select-panel');
 const flags = RendererStyleFlags2.Important + RendererStyleFlags2.DashCase;
 this.renderer.setStyle(element[0], 'min-width', `${this.offsetWidth}px`, flags); // offsetWidth is same as mat-form-field width
}

预期结果是在mat-select-panel类中添加了我的自定义计算最小宽度,但是实际上,它没有添加我的最小宽度。 Material auto会计算运行时并将其添加。

0 个答案:

没有答案