Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HTML Teil aus meinem Form für ein neues Horse:
- <div class="form-group">
- <label for="photo"></label>
- <input type="file"
- id="photo"
- (change)="handlePhotoUpload($event.target.files)">
- <img [src]="horse.photo" alt="<photo of horse>"/>
- </div>
- TypeScript Teil für Foto zu String konvertieren:
- handlePhotoUpload(files: FileList) {
- let photo = files.item(0);
- let fileReader = new FileReader();
- fileReader.readAsDataURL(photo);
- fileReader.onload = this.setPhotoString.bind(this);
- }
- setPhotoString(fileReader){
- let photoString = fileReader.target.result;
- this.horse.photo = photoString;
- }
- Des mit dem bind hab i vom gore weil sonst mit "this" net auf den component kommst sondern aufn FileReader. Sonst kannst this.horse.photo net setzen.
- Dann halt noch dem horse.ts an string fürs bild hinzufügen.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement