关于angular:记录遇到的问题

8次阅读

共计 613 个字符,预计需要花费 2 分钟才能阅读完成。

文件过大

写文件上传的时候,前台和后盾都遇到了文件过大的谬误。
前台用的是 nginx 转发, 后盾用的是 spring boot

前台:413 Request Entity Too Large” angular

后盾:

之后理解到,nginx 默认上传的最大 body 是 1M, 超过 1M 的数据申请就会报 413 谬误

解决:

在 nginx.conf 里设置配置:

server {
   client_max_body_size 20M;
   ...
}

angular 循环依赖

这里 HttpInterceptor 造成了循环依赖。

解决:

export class HttpErrorInterceptor implements HttpInterceptor {
  public static DONT_INTERCEPT_HEADER_KEY = 'http-error-do-not-intercept';
  thyNotifyService = this.injector.get(ThyNotifyService);

  constructor(private readonly injector: Injector) {}}

间接在构造函数中结构 Injector,而后再应用 this.injector.get(ThyNotifyService) 结构 service。

实际上,咱们间接获取了根注入器。再获取了注入器中的 service。

这样的话,以后的类就不会间接结构 ThyNotifyService,而是获取了根注入器。从而防止了循环依赖

正文完
 0