Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When I try to upload file from child component its not emitting the event of upload #506

Open
jayprajapati857 opened this issue Dec 4, 2019 · 0 comments

Comments

@jayprajapati857
Copy link

This method is in app.component.ts

startUpload(): void {
    const event: UploadInput = {
        type: 'uploadAll',
        url: 'http://test.com77s/8887',
        method: 'POST',
        data: {
            test: 'test'
        }
    }
    console.info('Starting upload', event, this);
    this.uploadInput.emit(event);
}

This code is in app component and I want to upload it using upload component which is child of app component.

When I try putting the directly to app component its working but when I try to do it from child its not working

<app-select-files (parentStartUploadButtonClick)="startUpload()"></app-select-files>

above app-select files is in app component

import { Component, OnInit, Output, EventEmitter } from '@angular/core';

@Component({
  selector: 'app-select-files',
  templateUrl: './select-files.component.html',
  styleUrls: ['./select-files.component.scss']
})
export class SelectFilesComponent implements OnInit {

  @Output() parentStartUploadButtonClick = new EventEmitter<any>();
  constructor() { }

  ngOnInit() {
  }

  protected startUploadButtonClick(event?: any): any {
    console.log(event);
    this.parentStartUploadButtonClick.emit(event);
  }

}

This app-select-files component html is given here

<div class="drop-container" ngFileDrop [options]="options" (uploadOutput)="onChildUploadOutput($event)" [uploadInput]="uploadInput" [ngClass]="{ 'is-drop-over': dragOver }">
    <h1>Drag &amp; Drop</h1>

    <label class="upload-button">
        <input type="file" ngFileSelect [options]="options" (uploadOutput)="onChildUploadOutput($event)"
            [uploadInput]="uploadInput" multiple>
        or choose file(s)
    </label>

    <button type="button" class="start-upload-btn" (click)="startUploadButtonClick($event)">
        Start Upload
    </button>
</div>

When I try to press the button start upload Its not uploading file. So when I debug the code in the parent of this component which is app component I found that the UploadInput EventEmitter has no Observers.

But when I try putting the html to upload the files in the app component its working.

Can anyone tell me what to do If I want to do it from the app-select-files component.

Thanks in Advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant