以来自垫选项的垫选择显示图像

时间:2018-11-21 12:59:52

标签: angular angular-material angular-material-6

因此,我有一段html,其中包含一个mat-form-field字段,该字段具有mat-select和mat-option。这些垫选项是从服务器生成的,当选择了一个选项时,它们需要在垫选择中显示一个图像(每个选项都有自己的图像)

jQuery(document).ready(function () {

    /*
     * windowSize
     * call this function to get windowSize any time
    */

    function windowSize() {
        windowHeight = window.innerHeight ? window.innerHeight : 
        $(window).height();
        windowWidth = window.innerWidth ? window.innerWidth : $(window).width();      
    }

    //Init Function of init it wherever you like...
    windowSize();

    // For example, get window size on window resize
    $(window).resize(function() {
        windowSize();
        //console.log("width is :", windowWidth, "Height is :", windowHeight);
        if (windowWidth > 1029) {
            $("#single-related").appendTo("#product-team-shop");
        } 
    });        
});

每当选择一个新选项时,我都想在选择垫中显示optionLabel和图像。

我已经了解了有关mat-select-trigger的信息,但对我没有任何帮助。

1 个答案:

答案 0 :(得分:0)

试着把这个:

<img height="24px" src="option[optionLabelImgKey]"/>

也许您的问题是由于无法访问img而导致文件无法显示(错误的路由)。

通过我在stackblitz上创建一个fork的方式,其中包含mat-select中的图像列表的工作示例,您可以查看一下: https://stackblitz.com/edit/angular-9txen8

相关问题