I have this jsFiddle: /
Which contains this html
<div ng-app ng:controller="ShowHideController">
<div ng-show='showMe'>
<img ng-src="{{imageSource}}"/>
</div>
<button ng-click='showImage()'> show image </button>
<div>
and this script:
function ShowHideController($scope) {
$scope.showMe = false;
$scope.imageSource = '';
$scope.showImage = function(){
$scope.showMe = true;
$scope.imageSource = '.png';
}
}
I'm getting a 404, image not found when the source has not yet been set, is there any way of preventing this when showMe is false?
I have this jsFiddle: http://jsfiddle/HMZuh/1/
Which contains this html
<div ng-app ng:controller="ShowHideController">
<div ng-show='showMe'>
<img ng-src="{{imageSource}}"/>
</div>
<button ng-click='showImage()'> show image </button>
<div>
and this script:
function ShowHideController($scope) {
$scope.showMe = false;
$scope.imageSource = '';
$scope.showImage = function(){
$scope.showMe = true;
$scope.imageSource = 'https://www.google./images/srpr/logo3w.png';
}
}
I'm getting a 404, image not found when the source has not yet been set, is there any way of preventing this when showMe is false?
Share Improve this question edited Nov 12, 2014 at 19:27 Mick MacCallum 130k40 gold badges281 silver badges281 bronze badges asked Sep 10, 2012 at 14:14 Hugo ForteHugo Forte 5,9785 gold badges37 silver badges47 bronze badges 3- Not having this problem - wondering if it's a browser issue. What browser are you trying this with? – Roy Truelove Commented Sep 10, 2012 at 15:48
- I tried it on chrome and firefox - both latest versions – Hugo Forte Commented Sep 10, 2012 at 19:26
- Sorry mate, tried this on a local project from scratch, never got the 404. – Roy Truelove Commented Sep 10, 2012 at 20:34
2 Answers
Reset to default 3To solve this you can:
- Use
ng-repeat
http://jsfiddle/bGA4T/ - Use $pile and declare your own directive
- Write your own
ng-src
directive - ...
I think there are many ways to solve this.
I improved on this by using ui-if from http://angular-ui.github./ Instead of hiding/showing using ng-hide/ng-show, ui-if simply does not render the element.
<div ui-hide='ImageHasBeenUploaded'>
<img ng-src='/some/image/path/{{imageName}}/>
</div>