HTML 在 AngularJS 加载之前发出请求

html makes a request before angularjs loads

本文关键字:请求 AngularJS 加载 HTML      更新时间:2023-09-26

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

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

但请求结果是:

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

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

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

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

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

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

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