2017-05-10 19 views
0

entfernen Ich habe die browserfile Eingang und Taste, um das Logo zu laden:wie kann ich Avatar in Winkel 2

<div class="col-md-2"> 
         <form #uploadLogo="ngForm" enctype="multipart/form-data" id="fileForm"> 
          <input type="file" 
            class="form-control" 
            nodisable 
            name="file" 
            id="companyLogo" 
            (change)="onChange($event)"> 
         </form> 
         <span class="thumbnail"><img *ngIf="data.companyObj.imagePath" 
          [src]="url + '/static/logo/' + data.companyObj.imagePath" height="50px" width="250px"/></span> 
        </div> 
        <div class="col-md-3"> 
         <button class="btn btn-primary" (click)="uploadCompanyLogo()">{{ 'BASEDATA.UPLOAD' | translate }}</button> 

und hier ist die TS-Datei:

public uploadCompanyLogo() { 
    if(this.file == null){ 
     this.fileUpload.uploadFile('/company-logo', 'companyLogo').subscribe(response => { 
     this.data.companyObj.imagePath = response.body.defaultLogo; 
     this.sharedService.setUrl(this.data.companyObj.imagePath); 
     }) 

wie kann ich diese entfernen mit removefunction und null sein

Antwort

1

Ich verstehe Ihre Frage nicht, aber wenn Sie Avatar entfernen möchten, nachdem Sie Ihre Arbeit getan haben, können Sie

setzen
data.companyObj.imagePath = null; 

Wenn Sie etwas anderes machen möchten, erklären Sie bitte mehr.

EDIT: Nach dem Erstellen neuer Löschtaste

<button class="btn btn-primary" (click)="removeCompanyLogo($event)"> 

Sie benötigen, um Ihre

data.companyObj.imagePath = null; 

zu machen, da Ihr Bild img ngIf hat, die auch von „data.companyObj.imagePath erstellt Ihr Bild "

<span class="thumbnail"> 
<img *ngIf="data.companyObj.imagePath [src]="url + '/static/logo/' + data.companyObj.imagePath" height="50px" width="250px"/> 
</span> 

so müssen Sie dies auf Ihrer ts-Datei

removeCompanyLogo (event) { 
    this.data.companyObj.imagePath = null; 
} 

Dies wird Ihren Avatar entfernt werden.

+0

danke, ich möchte nur eine andere Schaltfläche erstellen (klick) = "removeCompanyLogo() und dann in TS-Datei zum Erstellen der Funktion public removeCompanyLogo() –