This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from '@angular/core'; | |
@Component({ | |
selector: 'form', | |
templateUrl: ` | |
<form> | |
<input type="checkbox" (click)="selected($event)" | |
</form>`, | |
styleUrls: ['./form.scss'] | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function findAndRemove(array, item) { | |
const index = array.indexOf(item); | |
if(index>-1) { | |
array.splice(index, 1); | |
} | |
return array; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isInputValid(value, type) { | |
let valid; | |
let errorTxt; | |
switch(type) { | |
case 'email': | |
valid = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(value); | |
errorTxt = 'Enter a valida email'; | |
break; | |
case 'phone': | |
valid = /^([-0-9.()+ ]{5,50})*$/.test(value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from '@angular/core'; | |
import { FormBuilder, FormGroup } from '@angular/forms'; | |
@Component({ | |
selector: 'form', | |
templateUrl: ` | |
<form [formGroup]="form"> | |
<input type="text" formControlName="name"> | |
</form> | |
`, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
@Injectable() | |
export class SecurityService { | |
constructor() { } | |
sanitizeAllTags(text:string) { | |
return text.replace(/<[^>]*>/g, '*'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* wraps a promise in a timeout, allowing the promise to reject if not resolve with a specific period of time | |
* @param {integer} ms - milliseconds to wait before rejecting promise if not resolved | |
* @param {Promise} promise to monitor | |
* @Example | |
* promiseTimeout(1000, fetch('https://courseof.life/johndoherty.json')) | |
* .then(function(cvData){ | |
* alert(cvData); | |
* }) | |
* .catch(function(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 🔥 Node 7.6 has async/await! Here is a quick run down on how async/await works | |
const axios = require('axios'); // promised based requests - like fetch() | |
function getCoffee() { | |
return new Promise(resolve => { | |
setTimeout(() => resolve('☕'), 2000); // it takes 2 seconds to make coffee | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<style> | |
.item-header { | |
grid-area: header; | |
padding: 0px; | |
} | |
.item-btn-a { | |
grid-area: btnA; | |
padding: 0px; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Returns a list of objects | |
1. get the list of files to fetch | |
2. fetch each file to get the object | |
3. return an array of objects | |
*/ | |
getAll(): Observable<Tutorial[]> { | |
const list = this.dataSrv.getDataList() | |
.pipe( | |
// get list from dataList |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// EXAMPLE 1 | |
function resolveAfter2Seconds() { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
resolve('resolved'); | |
}, 2000); | |
}); | |
} |
OlderNewer