user1155141 user1155141 - 11 months ago 58
AngularJS Question

using ng-if to make p appear if image is null

I want to make a

appear if an image is missing from the image source. So if there is an image show the image if there is no image show the stuff in the

<div id="logo">
<img src="{{selected_.image}}">
<div ng-if="selected_.image == ''">

<p>hey<button ng-click="discardIntroPage();" class="button button-assertive">Add A Photo</button>">

Answer Source

Directive to handle images

var app = angular.module("app", []);

app.directive("imageLoading", function ($rootScope, $timeout) {
    return {
        restrict: "A",
        scope: {
          imageLoading: "="
        link: function (scope, element) {
            element.on("error", function () {
                scope.imageLoading = true;
<html ng-app="app">
    <h4>image 1</h4>
<img image-loading="google"  src="">
    <div ng-show="google">google image not found</div>
    <h4>image 2</h4>
<img image-loading="google2"  src="">
    <div ng-show="google2">google image not found</div>

    <script src=""></script>
<script src=""></script>