Skip to content

Instantly share code, notes, and snippets.

export class Filters {
public readonly format = 'JSON';
constructor(
public zone: 'ASI' | 'EUR' | 'USA',
public currency: 'EUR' | 'USD',
public userId: number
) { }
}
@AvocadoVenom
AvocadoVenom / remove-duplicates-1.js
Last active May 9, 2020 10:57
JS function to remove duplicates in array.
function removeDuplicates(arr) {
return arr.reduce((acc, cur) => {
if(acc.indexOf(cur) === -1) acc.push(cur);
return acc;
}, []);
}
@AvocadoVenom
AvocadoVenom / remove-duplicates-2.js
Created September 8, 2019 10:29
JS Function removing duplicates in an array using Set structure
function removeDuplicates(arr) {
return [...new Set(arr)];
}
const shape = {
radius: 10,
diameter() {
return this.radius * 2;
},
perimeter: () => 2 * Math.PI * this.radius
};
console.log(shape.diameter());
console.log(shape.perimeter());
@AvocadoVenom
AvocadoVenom / child.component.ts
Last active May 9, 2020 11:04
Several ways to make an angular child-to-parent communication
import { Component} from '@angular/core';
@Component({
selector: 'app-child',
template: `<h1>I am the child</h1>`
})
export class ChildComponent {
message = 'Hey there from the child!';
constructor() { }
}
@AvocadoVenom
AvocadoVenom / child.component.ts
Last active May 9, 2020 11:07
Child-to-parent communication using EventEmitter
import { Component, Output, EventEmitter } from '@angular/core';
@Component({
selector: 'app-child',
template: `
<button (click)="sendMessage()">Send Message</button>
`
})
export class ChildComponent {
message: string = "Hey there from the child!";
@AvocadoVenom
AvocadoVenom / child.component.ts
Created September 9, 2019 18:17
An angular child-to-parent communication using service.
import { Component, OnInit } from '@angular/core';
import { DataService } from "./data.service";
@Component({
selector: 'app-sibling',
template: `
{{message}}
<button (click)="newMessage()">New Message</button>
`
})
@AvocadoVenom
AvocadoVenom / overlay-loading.directive.ts
Last active January 20, 2023 06:40
Overlay Loading Directive > Directive
import { Directive, ElementRef, OnInit, Input } from '@angular/core';
import { OverlayRef } from '@angular/cdk/overlay';
import { DynamicOverlay } from '@app/third-parties/angular-material/dynamic-overlay';
import { Observable } from 'rxjs';
import { ComponentPortal } from '@angular/cdk/portal';
import { LoaderComponent } from './loader/loader.component';
@Directive({
selector: '[overlayLoading]'
})
@AvocadoVenom
AvocadoVenom / app.component.ts
Last active October 3, 2019 22:14
Overlay Loading DIrective > App Component
import { Component } from '@angular/core';
import { Overlay } from '@angular/cdk/overlay';
import { ComponentPortal } from '@angular/cdk/portal';
import { LoaderComponent } from './loader/loader.component';
@Component({
selector: 'app-root',
template:
`<mat-card>
<mat-card-header>
@AvocadoVenom
AvocadoVenom / loader.component.ts
Created October 3, 2019 22:12
Overlay Loading Directive > Loader Component
import { Component } from '@angular/core';
@Component({
selector: 'app-loader',
template:
`<mat-card>
<mat-card-header>
<mat-card-title>
Fetching data...
</mat-card-title>