Ich möchte Bedingung stellen, wenn ich Formular zu dieser Zeit Datei senden oder speichern Datei ändern Funktion aufrufen andernfalls nicht. Wie setze ich diese Bedingung in den unteren Code?Willst du Bedingung in upload Bild in angular2 setzen
ist diese Formularvorlage für das Hochladen von Bildern:
<form name="form" (ngSubmit)="f.form.valid && save()" #f="ngForm" novalidate enctype="multipart/form-data">
<div>
<input type="file" (change)="fileChange($event)" placeholder="Upload file">
<img [src]="employee.profile_image_url" height="50" width="50">
</div>
</from>
Es ist eine Form Sparfunktion in der Komponente:
save(): void {
if (this.employee.bank_details == null) {
this.employeeService.add_bankDetails(this.model, this.employee);
}
if (this.employee.current_address == null) {
this.employeeService.add_addressDetails(this.model, this.employee);
}
if (this.employee.permanent_address == null) {
this.employeeService.add_PaddressDetails(this.modelP, this.employee);
}
this.employee.full_name = (`${this.employee.first_name} ${this.employee.last_name}`);
this.employeeService.update(this.employee);
}
Its a filechange Ereignis für das Hochladen von Bildern in der Komponente:
fileChange(event: any) {
const imageFolder: string = this.employee.id;
const fileList: FileList = event.target.files;
const file: File = fileList[0];
const storageRef = firebase.storage().ref().child(`${imageFolder}/profile.jpg`).put(file)
.then((snapshot) => {
this.employee.profile_image_url = snapshot.downloadURL;
console.log(snapshot.downloadURL);
});
}
aus dem Code Ich verstehe, dass Sie filechange() aufrufen, aus dem Änderungsereignis des Eingangs. Nennen Sie es von der Funktion save() Senden ... – Vega
Ja, aber wie können Sie bitte erklären .. – Krunal