Use data uris for images

This commit is contained in:
Zakary Timson 2018-07-15 12:38:30 -04:00
parent 01a41c62b6
commit 453d42e1ae
2 changed files with 10 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import {BreadcrumbService} from './breadcrumb.service';
import {MatDialog} from '../../../node_modules/@angular/material'; import {MatDialog} from '../../../node_modules/@angular/material';
import {NewCategoryComponent} from './newCategory/newCategory.component'; import {NewCategoryComponent} from './newCategory/newCategory.component';
import {AppComponent} from '../app.component'; import {AppComponent} from '../app.component';
import {DomSanitizer} from '../../../node_modules/@angular/platform-browser';
@Component({ @Component({
selector: 'store', selector: 'store',
@ -21,6 +22,7 @@ export class CategoriesComponent {
private router: Router, private router: Router,
private route: ActivatedRoute, private route: ActivatedRoute,
private dialog: MatDialog, private dialog: MatDialog,
private domSanitizer: DomSanitizer,
public app: AppComponent, public app: AppComponent,
public breadcrumb: BreadcrumbService public breadcrumb: BreadcrumbService
) {} ) {}
@ -36,7 +38,13 @@ export class CategoriesComponent {
.valueChanges() .valueChanges()
.pipe( .pipe(
map(rows => map(rows =>
rows.filter((row: any) => (!this.category && !row.parent) || (this.category && row.parent == this.category)) rows
.filter((row: any) => (!this.category && !row.parent) || (this.category && row.parent == this.category))
.map((row: any) => {
row.image = this.domSanitizer.bypassSecurityTrustUrl(row.image);
console.log(row);
return row;
})
) )
); );
}); });

View File

@ -22,7 +22,7 @@ export class NewCategoryComponent {
imageChanged() { imageChanged() {
let reader = new FileReader(); let reader = new FileReader();
reader.addEventListener('load', (event: any) => (this.image = event.target.result)); reader.addEventListener('load', (event: any) => (this.image = event.target.result));
reader.readAsText(this.fileInput.nativeElement.files[0]); reader.readAsDataURL(this.fileInput.nativeElement.files[0]);
} }
submit() { submit() {