[英]AngularJS doesn't update img src when model changes
我使用ng-src
加載圖像。 值從某個范圍變量加載,如下所示:
<img ng-src="{{currentReceipt.image}}"/>
我的問題是,當我運行delete $scope.currentReceipt
,它使ng-src
屬性為空,但不會在src
屬性中反映出來。 因此,我一直看到我需要空占位符的圖像。
我怎么處理它?
在刪除$ scope.currentReceipt之后調用$ scope。$ apply()。
以下解決方案適合我:
<img ng-src="{{currentReceipt.image}}" ng-show="currentReceipt.image != null" />
你可以實際檢查長度和做
<img ng-show="user.thumbnail.length > 1" class="img-circle thumb pull-left" ng-src="{{user.thumbnail}}" alt="{{user.firstname}} {{user.lastname}}">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.