Best way to preload images with Angular.js

前端 未结 9 904
野性不改
野性不改 2020-12-07 16:04

Angular\'s ng-src keeps previous model until it preloads image internally. I am using different image for the banner on each page, when I switch routes, i change main view,

9条回答
  •  一个人的身影
    2020-12-07 16:28

    A simple solution I've found is to change the url to '//:0' before assigning it's new value

    $scope.bannerUrl = 'initial value'; 
    
    // When we want to change it
    $scope.bannerUrl = '//:0';  // remove the previous img so it's not visible while the new one loads
    $scope.bannerUrl = scope.preloadedUrl
    

提交回复
热议问题