// Code goes here
angular
.module('imgapp', [])
.controller('mainCtrl', mainCtrl);
function mainCtrl() {
var vm = this;
vm.first = {
title: 'Image 1',
url: 'http://www.image-mapper.com/photos/original/missing.png'
}
vm.second = {
title: 'Image 2',
url: 'http://www.keenthemes.com/preview/conquer/assets/plugins/jcrop/demos/demo_files/image1.jpg'
}
vm.primary = vm.first;
vm.changeObject = function() {
vm.primary = vm.second;
}
}
<html ng-app="imgapp">
<head>
<script data-require="angular.js@1.4.9" data-semver="1.4.9" src="https://code.angularjs.org/1.4.9/angular.js"></script>
<script src="script.js"></script>
</head>
<body ng-controller="mainCtrl as vm">
<button ng-click="vm.changeObject();">Change object</button>
<h1>{{vm.primary.title}}</h1>
<img ng-src="{{vm.primary.url}}">
</body>
</html>
I have a block with a title and an image in it. Data in this block can be changed, therefore another image should be loaded.
If you have slow internet connection, you can see that the title was changed, where image wasn't, cause it hasn't loaded yet.
Demo: (press change object
to load a new image and change the title)
How can I hide an old image until a new image has been loaded?
Note: I don't use jQuery