Javascript 防止图像在AngularJs中渲染

Javascript 防止图像在AngularJs中渲染,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,我有这个问题: 其中包含此html <div ng-app ng:controller="ShowHideController"> <div ng-show='showMe'> <img ng-src="{{imageSource}}"/> </div> <button ng-click='showImage()'> show image </button> <div>

我有这个问题:

其中包含此html

<div ng-app ng:controller="ShowHideController">
    <div ng-show='showMe'>
        <img ng-src="{{imageSource}}"/>
    </div>
    <button ng-click='showImage()'> show image </button>
<div>
我得到了一个404,当源代码还没有设置时找不到图像,当showMe为false时,有没有办法防止这种情况发生

要解决此问题,您可以:

  • 使用
    ng repeat
  • 使用并声明您自己的指令
  • 编写自己的
    ng src
    指令

  • 我认为有很多方法可以解决这个问题。

    我通过使用ui if from对此进行了改进 ui if不使用ng hide/ng show隐藏/显示元素,而只是不呈现元素

    <div ui-hide='ImageHasBeenUploaded'>
        <img ng-src='/some/image/path/{{imageName}}/>
    </div>
    
    
    
    没有此问题-不知道这是否是浏览器问题。你用的是什么浏览器?我在chrome和firefox上试用过,都是最新版本对不起,mate,在本地的一个项目上从头开始试用过,但没有得到404。谢谢,我最终使用了ng repeat,解决了这个问题。不完全是我想要的,但它起了作用=)
    <div ui-hide='ImageHasBeenUploaded'>
        <img ng-src='/some/image/path/{{imageName}}/>
    </div>