我在我的网站中使用 AngularJS,一些图像的加载方式如下:
<img ng-cloak src="{{ person.username }}"/>
问题是我在控制台中收到 404 错误,表示找不到图像,因为在加载 Angular 之前,它会尝试加载名为 {{ person.username }}
如何解决这个问题?
最佳答案
使用ng-src
Using Angular markup like {{hash}} in a src attribute doesn't work right: The browser will fetch from the URL with the literal text {{hash}} until Angular replaces the expression inside {{hash}}. The ngSrc directive solves this problem.
<img ng-cloak ng-src="{{ person.username }}"/>
关于angularjs - 加载名称取决于 AngularJS 变量的图像时找不到资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31155379/