Skip to content

Instantly share code, notes, and snippets.

View Mustafa-Omran's full-sized avatar
💭
I may be slow to respond.

Mustafa Omran Mustafa-Omran

💭
I may be slow to respond.
  • Egypt
View GitHub Profile
@Mustafa-Omran
Mustafa-Omran / update.service.ts
Created March 14, 2022 11:08
Angular - Service Worker (Dealing With Updates)
import { Injectable } from '@angular/core';
import { MatSnackBar } from '@angular/material/snack-bar';
import { SwUpdate } from '@angular/service-worker';
@Injectable()
export class UpdateService {
constructor(private swUpdate: SwUpdate,
private snackbar: MatSnackBar) {
this.swUpdate.available.subscribe(event => {
@Mustafa-Omran
Mustafa-Omran / no-white-space.ts
Created March 14, 2022 09:16
Angular - No white spaces
import { FormControl } from "@angular/forms";
export function noWhitespaceValidator(control: FormControl) {
const isWhitespace = (control.value || '').trim().length === 0;
const isValid = !isWhitespace;
return isValid ? null : { 'whitespace': true };
}
@Mustafa-Omran
Mustafa-Omran / language.service.ts
Created February 28, 2022 07:56
Angular - Language Service
import { Injectable, Inject } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
import { TranslateService } from '@ngx-translate/core';
import { DOCUMENT } from '@angular/common';
@Injectable({
providedIn: 'root'
})
export class LanguageService {
private readonly DEFAULT_LANGUAGE = 'en';
@Mustafa-Omran
Mustafa-Omran / autocomplete-off.html
Created February 23, 2022 12:36
HTML - Disable autocomplete suggestions
<input type="text" autocomplete="off" autocomplete="chrome-off">
@Mustafa-Omran
Mustafa-Omran / demo.html
Last active February 23, 2022 15:11
Angular - Custom directive to accept only positive numbers within inputs
<!-- keep it as text to hide arrow up and down -->
<!-- user can add negative numbers if type number -->
<input type="text" positiveNumbers>
@Mustafa-Omran
Mustafa-Omran / export-to-pdf.html
Last active June 27, 2024 15:22
Angular - Export Multiple Pages with PDF format - Using jsPDF && html2canvas packages
<div id="print-section">
<!-- template here -->
</div>
@Mustafa-Omran
Mustafa-Omran / filter.html
Created February 21, 2022 10:03
Angular - Filter Tables Or any List using Shared Custom Pipe Filter
<mat-option *ngFor="let value of list | filter:searchKeywords" [value]="value.id" matTooltip="{{value.name}}">
{{value.name}}
</mat-option>
@Mustafa-Omran
Mustafa-Omran / angular-reactive-form-array.html
Last active January 20, 2024 07:22
angular - Reactive Forms Array (dynamic rows)
<form [formGroup]="form">
<div formArrayName="students" *ngFor="let student of students.controls; let index = index; let last = last">
<mat-card [formGroupName]="index">
<mat-card-title>
<p>student #{{index + 1}}</p>
<mat-icon (click)="removeStudent()" class="remove">delete</mat-icon>
</mat-card-title>
<mat-card-content>
<mat-form-field>
@Mustafa-Omran
Mustafa-Omran / Angular - OSM Search Service (nominatim).ts
Last active February 21, 2022 09:29
OpenStreetMap - Search service (nominatim)
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class SearchService {
private static readonly endpoint = 'https://nominatim.openstreetmap.org/search?format=json';
@Mustafa-Omran
Mustafa-Omran / environment.ts
Last active February 21, 2022 09:25
Angular - Set Http Client
const settings: Settings = {
backendUrl: 'http://...',
};