javascript Ng-src 不适用于本地存储的图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24858200/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 03:27:29  来源:igfitidea点击:

Ng-src not working for locally stored image

javascriptjqueryhtmlangularjs

提问by Nakul Pathak

I'm trying something in angularjs. This is the controller I made:

我正在 angularjs 中尝试一些东西。这是我制作的控制器:

function ImagesController($scope){
    $scope.count = 0;
    $scope.imags = [
        {
            image1: 'images/levels/level1/sky.jpg',
            image2: 'images/levels/level1/rain.jpg',
            image3: 'images/levels/level1/sky.jpg'
        },
        {
            image1: 'images/levels/level2/x.jpg',
            image2: 'images/levels/level2/y.jpg',
            image3: 'images/levels/level2/z.jpg'
        }
    ];
  }

And this is the HTML linking to this controller:

这是链接到该控制器的 HTML:

<div ng-controller="ImagesController">
      Random Writing
        <img ng-src="$scope.imags[0].image1">
 </div>

I don't know why the image that I'm trying to display is not working. I have added ng-app to the tag already so that can't be the issue.

我不知道为什么我试图显示的图像不起作用。我已经将 ng-app 添加到标签中,所以这不是问题。

回答by Gustav

I belive you should write

我相信你应该写

   <img ng-src="{{imags[0].image1}}>

Link to the directives documentation

链接到指令文档