简体   繁体   English

如何在离子角度的ng2上传中将id传递给URL

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

I want to pass userID as a parameter in URL in the ng2Upload package.我想在 ng2Upload 包中将 userID 作为参数传递给 URL。 Below is my TS CODE:以下是我的 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
  });
}

I want to append the userId variable to the url.我想将 userId 变量附加到 url。 Bt it is giving error as Property 'userid' is used before its initialization. Bt 它给出了错误,因为在初始化之前使用了属性 'userid'。

The UserId was never initialized, it was only declared. UserId 从未被初始化,它只是被声明。 and I don't how the uri was also gonna work, so made a few changes.我不知道 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 });
    });
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM