Vinícius Mussato
Vinícius Mussato

Reputation: 358

Img src doesn't change when i updated the source

I have an ionic 1 app and im trying to dynamically change a img source. I thought all i had to do whas update the scope linked to this source, but it doesn't worked. Any idea on what might be wrong?

my View
<div ng-if="isList" class="item style-list" ng-repeat="(key, item) in items"
       ng-click="goTo(item)">
            <div class="img-container" ng-if="isList">
                <m-img encode="true" src="item.image"></m-img>
            </div>
    <h1 ng-bind="item.title"></h1>
            <p ng-bind="item.resume" ng-if="item.resume"></p>
            <p ng-bind-html="stripHtml(item.description) | mCut:100" ng-if="!item.resume"></p>
  </div>

my Controller
     $scope.$on("update-data", function(event, args) { 

      $scope.items[1].description = 
      args.response.results[0].item.description;
      $scope.items[1].id = args.response.results[0].item.id;
      $scope.items[1].image = args.response.results[0].item.image;
      $scope.items[1].resume = args.response.results[0].item.resume;
      $scope.items[1].title = args.response.results[0].item.title;

    });

My m-img component

html
<div class="thumb-size notloaded">
  <div class="thumb" ng-if="imgStyle" ion-img-cache-bg ng-
style="imgStyle">
    </div>
</div>

My m-img JS is kinda extensive, here https://codeshare.io/adABMe

Upvotes: 1

Views: 675

Answers (1)

Karim
Karim

Reputation: 8632

it seems that the error is inside mImg component, from the code here you're not watching changes on src attribute (but you're doing it only on url attribute that here is not used) and you're triggering some logic (defined in $scope.load) to update the view.

You should add a watcher even on src and trigger your load method to update $scope.imgSrc variable , this should update your view consequently

controller: function($scope, $timeout, $mAppDef) {
   $scope.$watch('src', function() {
     $scope.load()
   });
}

Upvotes: 1

Related Questions