Skip to content

Instantly share code, notes, and snippets.

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

Nicolas Fazio FazioNico

🏴‍☠️
View GitHub Profile
@FazioNico
FazioNico / release.project.sh
Last active January 8, 2018 22:49
git repository release script
# @Author: Nicolas Fazio <webmaster-fazio>
# @Date: 20-10-2017
# @Email: contact@nicolasfazio.ch
# @Last modified by: webmaster-fazio
# @Last modified time: 08-01-2018
# @Url: https://gist.github.com/FazioNico/e22a09144cad8de05d74b7b3bcc6004e
# release script v.0.1.0
# git repository config
@FazioNico
FazioNico / Dockerfile.ng-docker
Created February 7, 2018 07:20
Develope with angular-cli into a Docker container
FROM node:8.9.4
ENV NODE_VERSION 8.9.4
# RUN useradd --user-group --create-home --shell /bin/false app
ENV HOME=/home/app
WORKDIR $HOME
RUN npm config set user 0
RUN npm config set unsafe-perm true
RUN npm install -g @angular/cli
EXPOSE 4200 49153
export class HelloWorld extends HTMLElement {
render(): string {
return `hello world`;
}
connectedCallback(): void {
this.textContent = this.render();
}
}
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>
@FazioNico
FazioNico / angular-reactive-form-basic.ts
Last active October 28, 2019 13:23
Simple & Basic Angular Reactive form example
import { Component, OnInit } from '@angular/core';
import { Validators, FormGroup, FormControl } from '@angular/forms';
@Component({
selector: 'my-component',
template: `
<form [formGroup]="form">
<input formControlName="email" name="email" type="email" /> <br/>
<input formControlName="pwd" name="pwd" type="password" /> <br/>
<button (click)="submit()">Submit</button>
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>
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();
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();
// 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();
});
}