I have this jsFiddle: http://jsfiddle.net/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.com/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?
This tutorial shows multiple examples in Angular, One example is to load images using the img tag Another example is to bind the src attribute to the assets folder. Normally, Images are placed in the src/assets folder in the Angular application.
If images do not display correctly, check src/assets folder is included inside the assets attribute in the angular.json file of your angular application. Check path relevant HTML file location with the assets folder
The Img tag is used to display an image on an angular application. It is declared in the HTML template file. src contains the absolute path of images that referred from the HTML file alt contains string content to display on image for SEO purpose
Ultimately, the issue was that the width of the navbar-header and the profile-dropdown elements were being calculated using JavaScript in an AngularJS directive after the DOM was loaded and whenever there was a page resize in the link function, something like this.
To solve this you can:
ng-repeat
http://jsfiddle.net/bGA4T/ ng-src
directiveI think there are many ways to solve this.
I improved on this by using ui-if from http://angular-ui.github.com/ 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With