Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/412.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 来自变量的Ionic3背景图像_Javascript_Css_Angular_Ionic2_Ionic3 - Fatal编程技术网

Javascript 来自变量的Ionic3背景图像

Javascript 来自变量的Ionic3背景图像,javascript,css,angular,ionic2,ionic3,Javascript,Css,Angular,Ionic2,Ionic3,我正在使用ngFor输出一组帖子。每个都应该有一个背景图像。 getBackgroundStyle从帖子中提取图像的URL(这是一个数组) 现在,有趣的是,在构建之后,img标记可以正常工作,而div完全松开了样式标记 在实验室/浏览器中输出: <div class="singlePost"> <div> <img src="http://theurl.com"> 使用属性绑定: <div [ngStyle]="{ back

我正在使用ngFor输出一组帖子。每个都应该有一个背景图像。 getBackgroundStyle从帖子中提取图像的URL(这是一个数组)


现在,有趣的是,在构建之后,img标记可以正常工作,而div完全松开了样式标记

在实验室/浏览器中输出:

<div class="singlePost">
    <div>
        <img src="http://theurl.com">

使用属性绑定

<div [ngStyle]="{ background-image: 'url(' + getBackgroundStyle(post) + ')' }"></div>


对于图像元素也应该这样做:

<img [src]="getBackgroundStyle(post)">

<div [style.background-image]="'url(' + getBackgroundStyle(post) + ')'"></div>
<img [src]="getBackgroundStyle(post)">