Skip to content

Instantly share code, notes, and snippets.

@pawankkumawat
Created March 3, 2022 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawankkumawat/605087175dc267b6b38acf9892cd834a to your computer and use it in GitHub Desktop.
Save pawankkumawat/605087175dc267b6b38acf9892cd834a to your computer and use it in GitHub Desktop.
Strategy Pattern in Angular
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `
<h1>Strategy design Pattern</h1>
<mat-slide-toggle color="primary" [checked]="true" (change)="toggleHandler($event.checked)">
Compress Images
</mat-slide-toggle> <br><br><br>
<input type="file" accept="image/*" multiple="" id="file" (change)="uploadFile($event)" />
`,
})
export class AppComponent {
isChecked = true;
toggleHandler(isChecked: boolean) {
this.isChecked = isChecked;
}
uploadFile(event) {
const filesArray = Array.from((<HTMLInputElement>event.target).files);
this.isChecked
? this.compressAndProcessFiles(filesArray)
: this.processFiles(filesArray);
}
compressAndProcessFiles(filesArray: File[]) {
console.log('processing compressed files');
}
processFiles(filesArray: File[]) {
console.log('processing files');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment