0
我的角度網站從Web API後端獲取數據,最初顯示一般背景。但是登錄後,客戶背景圖像url被檢索並用於我的ng樣式屬性。Angular ng風格增加了一個風格屬性,然後不保持同步
當頁面初始加載時,還會出現一個不屬於源代碼的樣式屬性,該屬性將背景指向默認圖像。
但是,登錄後,即使ng樣式現在顯示正確的背景圖像url,style屬性仍然指向默認的url。
如果我手動刷新頁面(Chrome中的開發人員設置中沒有緩存),則更新style屬性並正確顯示客戶背景。
發生了什麼事?爲什麼會角色添加一個樣式屬性,然後不保持同步?
源代碼
<div class="background-div" ng-style="{'background-image': 'url({{user.profile.Customer.BackgroundImageUrl || '../images/bg.jpg'}})'}"></div>
初始頁面加載
<div class="background-div" ng-style="{'background-image': 'url(../images/bg.jpg)'}" style="background-image: url(http://localhost:10223/images/bg.jpg);"></div>
後登錄
<div class="background-div" ng-style="{'background-image': 'url(http://megacorp.com/images/vipcustomer.jpg)'}" style="background-image: url(http://localhost:10223/images/bg.jpg);"></div>
被迫無緩存刷新
<div class="background-div" ng-style="{'background-image': 'url(http://megacorp.com/images/vipcustomer.jpg)'}" style="background-image: url(http://megacorp.com/images/vipcustomer.jpg);"></div>
固定碼
<div class="background-div"
ng-style="{'background-image': 'url(' + (user.profile.Customer.BackgroundImageUrl || '../images/bg.jpg') + ')'}">
</div>
重新打開後:
恕我直言,這個問題是不同的B/C它停留在HTML和不進入$摘要和腳本,並顯示頁面處於不同狀態的階段。但我依照你的判斷:)
我不得不把括號周圍的表達,因此將在連接前做OR。然後它工作。看到我的編輯顯示修復。謝謝! – toddmo
@toddmo不會在'ng樣式中使用插值括號' –
我的意思是我必須放置'('和')',而不是'{{'和'}}'。謝謝! – toddmo