在6.0版本的PrimeNG的upload控件中上傳使用的是http而非HTTPClient创千,因此在angular的Interceptor中攔截不到讯榕。
可在onBeforeSend事件中對(duì)請(qǐng)求頭進(jìn)行修改
<p-fileUpload name="fileName" [url]="uploadDailyDataUrl" chooseLabel="選擇文件" uploadLabel="上傳文件" cancelLabel="取消上傳"
method="post" (onUpload)="onUpload($event)" multiple="multiple" (onBeforeSend)="onBeforeSend($event)">
</p-fileUpload>
onBeforeSend(event) {
this.xhr = event.xhr;
this.xhr.setRequestHeader("Authorization", localStorage.getItem("sessionId"));
}