如何在 ionic angular 中的 ng2 上传中将 id 传递给 URL

how to pass an id to a URL in ng2 upload in ionic angular

我想在 ng2Upload 包的 URL 中将 userID 作为参数传递。 以下是我的 TS 代码:

import { Component, OnInit } from '@angular/core';
import { Storage } from '@ionic/storage';
import { FileUploader, FileSelectDirective } from 'ng2-file-upload/'; 
import { environment } from '../../environments/environment';

var uri = 'http://localhost:4000/prescription/upload/';
@Component({
  selector: 'app-prescribtion',
  templateUrl: './prescribtion.page.html',
  styleUrls: ['./prescribtion.page.scss'],
})
export class PrescribtionPage implements OnInit {
  image;
  imageData;
  userid: any;
  id: string;
  attachmentList: any = [];
  constructor(private storage: Storage) {}

  ngOnInit() {
    this.storage.get('userid').then((userid) => {
      this.userid = userid;
      uri = uri + userid;
      console.log(uri);
    });
  }

  public uploader: FileUploader = new FileUploader({
    url: uri
  });
}

我想将 userId 变量附加到 url。 Bt 它给出了错误,因为在初始化之前使用了 属性 'userid'。

UserId 从未被初始化,它只是被声明了。而且我不知道 uri 是如何工作的,所以做了一些更改。

export class PrescribtionPage implements OnInit {
  image;
  imageData;
  userid: any = null;
  id: string;
  attachmentList: any = [];
  constructor(private storage: Storage) {}
  public uploader: FileUploader;


  ngOnInit() {
    this.storage.get('userid').then((userid) => {
      this.userid = userid;
      var uri: string = "https://whatever.uri.com";
      uri = uri + userid;
      console.log(uri);
      this.uploader = new FileUploader({ url: uri });
    });
  }
}