簡體   English   中英

AngularJS如何在模板HTML中引用本地圖像

[英]Angularjs how to refer a local image in template html

我正在嘗試將本地圖像加載為CSS中的背景圖像。 我的文件夾結構如下

MyApp
    Public
        index.html
    html
        template.html
    images
        myimage.png
    javascripts
    stylesheet

從公用文件夾加載index.html ,然后單擊,從html文件夾加載template.html 我在template.html中定義了這樣的CSS,

textarea{
<!-- background-image: url(http://i.imgur.com/2cOaJ.png); -->
background-image: url('../images/myimage.png');
background-attachment: local;
background-repeat: no-repeat;
padding-left: 35px;
padding-top: 10px;
border-color:white;
background-color: white; 
height:90%;
width:95%;
resize: none;
outline-width: 0;
}

然后在template.html中將其稱為,

<div id="bodydata" class="tabcontent" >
      <textarea rows="5" ng-model="description"></textarea>
</div>  

當我從網絡上拍攝圖像"background-image: URL(http://i.imgur.com/2cOaJ.png);"時,它效果很好"background-image: URL(http://i.imgur.com/2cOaJ.png);" 但是當我更改為本地映像時,該映像不起作用,只不過是下載並保存為本地副本的同一映像。

background-image: url('../images/myimage.png');

我希望將其作為本地服務器,因為服務器可能沒有互聯網連接。 因此,如何以正確的方式引用圖像。 我已經嘗試了很多東西,例如單引號,雙引號,不帶引號,但是它沒有用。 請提出建議。

提前致謝。

您的網絡服務器如何設置? 您的Web服務器從哪里運行?

根據這些答案,您應該能夠通過調整CSS來獲得所需的結果,如下所示:

background-image: url('/images/myimage.png');

因此,例如,如果您的Web服務器在/ MyApp中運行,並且配置為允許提取靜態文件(例如,與該模式/images/*.png匹配的文件),那么上面的答案應該可以使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM