Skip to content

Instantly share code, notes, and snippets.

View FazioNico's full-sized avatar
🏴‍☠️

Nicolas Fazio FazioNico

🏴‍☠️
View GitHub Profile
@FazioNico
FazioNico / ng-ol.component.ts
Created May 18, 2020 08:32
Component to display Open Layer Map with Angular
import { Component, Input, AfterViewInit, Output, EventEmitter, ViewChild, ElementRef, ChangeDetectorRef } from '@angular/core';
import olMap from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import XYZ from 'ol/source/XYZ';
import WebGLPointsLayer from 'ol/layer/WebGLPoints';
import { LiteralStyle, SymbolType } from 'ol/style/LiteralStyle';
import { Feature } from 'ol';
import { fromLonLat } from 'ol/proj';
import Point from 'ol/geom/Point';
export const flatMap = (fn, arr: any[]): any[] => [].concat.apply([], arr.map(fn));
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({name: 'groupBy'})
export class GroupByPipe implements PipeTransform {
transform(value: Array<any>, objKey: string): Array<any> {
// prevents the application from breaking if the array of objects doesn't exist yet
if (!value) {
return null;
}
const groupedCollection = value.reduce((previous, current) => {
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class CSVService {
async toJSON(str: string, delimiter: string) {
// `\\${delimiter}(?=\S)\\`
const regExp = new RegExp(delimiter);
// créer une class qui extend HTMLElement
class UserDetailsCard extends HTMLElement {
constructor() {
super();
// Ajouter un click listener sur notre component
this.addEventListener('click', e => {
this.toggleDetails();
});
}
const userData = async (id = 1) => {
const user = await fetch(`https://reqres.in/api/users/${id}`)
.then(res => res.json())
.then(res => (res && res.data) ? res.data : null);
console.log(user);
return user;
}
userData();
const userData = (id = 1) => {
const user = fetch(`https://reqres.in/api/users/${id}`)
.then(res => res.json())
.then(res => (res && res.data) ? res.data : null);
console.log(user);
return user;
}
userData();
import { Component, OnInit, Input, HostListener, ElementRef } from '@angular/core';
import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';
@Component({
selector: 'app-file-upload',
template: `
<div>
<span>Choose file</span>
<span>{{file ? file.name : 'or drag and drop file here' }}</span>
<input class="file-input" type="file">
@FazioNico
FazioNico / app-file-upload.component.ts
Last active October 28, 2019 22:10
angular-upload-file-reactive-form.ts
import { Component, OnInit, Input, HostListener, ElementRef } from '@angular/core';
@Component({
selector: 'app-file-upload',
template: `
<div>
<span>Choose file</span>
<span>{{file ? file.name : 'or drag and drop file here' }}</span>
<input class="file-input" type="file">
</div>
import { Component, OnInit } from '@angular/core';
import { Validators, FormGroup, FormControl, FormArray } from '@angular/forms';
@Component({
selector: 'my-component',
template: `
<form [formGroup]="form">
<ul formArrayName="items">
<li [formGroupName]="i" *ngFor="let itemCtrl of form.get('items')?.controls; let i = index" >
<input formControlName="title" name="title" type="text" /> <button (click)="removeItem(i)">X</button>