【问题标题】:html makes a request before angularjs loadshtml 在 angularjs 加载之前发出请求
【发布时间】:2014-12-12 02:28:13
【问题描述】:

我在 html 中放了一个 http 请求,如下所示:

<img src="/api/profilepic/user/{{user.id}}">

但请求结果是:

Request URL:https://example.com/api/profilepic/user/%7B%7Buser.id%7D%7D

最终,它会一直发送请求,直到 angular 和 user.id 被初始化。但在此之前,我的节点服务器会出现一堆错误。有谁知道如何解决这个问题?

我尝试像下面这样使用 ng-switch,但它也不起作用。

<div ng-switch="user.id != null">
  <div ng-switch-when="true">                                                                     
    <img src="/api/profilepic/user/{{user.id}}">
  </div>
</div>

【问题讨论】:

  • 改用ng-src

标签: javascript html angularjs dom


【解决方案1】:

src 属性中使用AngularJS 句柄时,应将其替换为ng-src

<img ng-src="/api/profilepic/user/{{user.id}}">

Angular 文档是你的朋友:https://docs.angularjs.org/api/ng/directive/ngSrc

【讨论】:

    猜你喜欢
    • 2018-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多