4
votes

I'm using file upload from PrimeNG : https://www.primefaces.org/primeng/#/fileupload

For now, I have this enter image description here

But I would like to have only "Choose" and "Cancel" buttons. enter image description here

So on primeNG website, they say to use showUploadButton="false"

But it's not working.

Refering to this post : Remove File Upload and Cancel Button from Primefaces p:fileUpload

I tried :

<p-fileUpload ...  showButtons="false" showCancelButton="true"/>

then I tried

.ui-fileupload-buttonbar .ui-fileupload-upload {
    display: none;
}

Nothing works. Maybe it's because it was refering to another version. I'm using version of primeNG 2.0.6 and angular 2.4.0

6

6 Answers

20
votes

You have to put the showUploadButton inside of a bracket for it to work.

<p-fileUpload [showUploadButton]="false"></p-fileUpload>

Result

EDIT: You need to get the latest version of PrimeNG to work with Angular 4. Since Angular launched their Angular 4, PrimeNG has also launched PrimeNG v4 to work with Angular 4

2
votes

have you tried to do like this:

<p:fileUpload ...  [showButtons]="false" [showCancelButton]="true"/>

Hope it helps you

0
votes

The only solution working for me was to hide it with css :

.ui-fileupload-buttonbar button:nth-child(2){
  display:none;
}
0
votes

using FileUploader from ng2-file-upload, in .html :

<tr *ngFor="let item of uploader.queue let i = index">
    <td>
      <div *ngIf= "!uploader.queue[i].isUploaded">
       <button type="button" class="btn btn-success btn-xs" style="margin:2px" (click)="onSubmit(i,item,$event.target)" >
        <span class="glyphicon glyphicon-upload"></span> Upload
       </button>
      </div>
    </td>
 </tr>

In the component.ts

    public index:number ;
    public onFileSelected() {
      this.uploader.queue[this.index].isUploaded=false; // initializing uploaded to false
    }

    public onSubmit(index:number){
      this.uploadService.uploadFile(this.csvJsonData).subscribe((responseData)=>{
      this.onSubmitresponse = responseData ;
      if(this.onSubmitresponse.status==201){
        this.uploader.queue[index].progress = 100;
        this.toastrService.success('The File has been uploaded successfully !',this.onSubmitresponse.status,{positionClass:'toast-bottom-center'});

        this.uploader.queue[index].isUploaded=true;// will hide the upload button
      }
     else this.toastrService.error(this.onSubmitresponse.errorMessage,this.onSubmitresponse.status,{positionClass:'toast-bottom-center'});
    });

  }
0
votes

To hide BUTTONBAR:

::ng-deep .p-fileupload .p-fileupload-buttonbar {
    display:none;
}

To hide CONTENT files:

::ng-deep .p-fileupload .p-fileupload-content {
    display:none;
}
-1
votes

[showUploadButton]="false" [showCancelButton]="false"