File

src/app/components/users/photo/photo.component.ts

Metadata

selector app-photo
styleUrls photo.component.css
templateUrl photo.component.html

Inputs

Photos

Type: Photo[]

Constructor

constructor(authService: AuthService)

Methods

Public fileOverBase
fileOverBase(e: any)
Returns: void
initUploader
initUploader()
Returns: void

Properties

baseUrl
baseUrl: string
hasAnotherDropZoneOver
hasAnotherDropZoneOver: boolean
Default value: false
hasBaseDropZoneOver
hasBaseDropZoneOver: boolean
Default value: false
uploader
uploader: FileUploader
import { Component, OnInit, Input } from "@angular/core";
import { Photo } from "../../../_models/Photo";
import { FileUploader } from "ng2-file-upload";
import { environment } from "../../../../environments/environment";
import { AuthService } from "../../../_services/auth.service";
@Component({
  selector: "app-photo",
  templateUrl: "./photo.component.html",
  styleUrls: ["./photo.component.css"]
})
export class PhotoComponent implements OnInit {
  baseUrl = environment.apiUrl;
  @Input() Photos: Photo[];

  uploader: FileUploader;
  hasBaseDropZoneOver: boolean = false;
  hasAnotherDropZoneOver: boolean = false;

  constructor(private authService: AuthService) {}

  ngOnInit() {
    this.initUploader();
  }

  public fileOverBase(e: any): void {
    this.hasBaseDropZoneOver = e;
  }

  initUploader() {
    this.uploader = new FileUploader({
      url:
        this.baseUrl +
        "users/" +
        this.authService.decodedToken.nameid +
        "/photos",
      authToken: "Bearer " + localStorage.getItem("token"),
      isHTML5: true,
      allowedFileType: ["image"],
      removeAfterUpload: true,
      autoUpload: false,
      maxFileSize: 10 * 1024 * 1024
    });
    this.uploader.onSuccessItem = (item, response, status, headers) => {
      if (response) {
        const res: Photo = JSON.parse(response);
        const photo = {
          id: res.id,
          url: res.url,
          dateAdded: res.dateAdded,
          isMain: res.isMain
        };
        this.Photos.push(photo);
      }
    };
  }
}

results matching ""

    No results matching ""