Skip to content

Instantly share code, notes, and snippets.

@afrozek
afrozek / Angular get all form errors
Created May 24, 2023 20:45
Angular get all form errors
getAllErrors(form: FormGroup | FormArray): { [key: string]: any } | null {
// validation via form model
let hasError = false;
const result = Object.keys(form.controls).reduce((acc, key) => {
const control = form.get(key);
// console.log('control', control);
const errors = control instanceof FormGroup || control instanceof FormArray ? this.getAllErrors(control): control.errors;
if (errors || control.status === 'INVALID') {
acc[key] = errors;
hasError = true;
@afrozek
afrozek / comp.sh
Last active November 9, 2016 01:15
Bash script to create/generate angular modules along with controllers, services and directives
#!/bin/bash
# Bash script to generate new angular modules
# Just go into the desired directory and type
# sh comp.sh nameOfModule
# Will create a directory and the module, controller, factory, and directive
mkdir $1
cd $1
cat <<EOF >> $1".module.js"
(function() {
//source: http://blog.guya.net/2015/06/12/sharing-sessionstorage-between-tabs-for-secure-multi-tab-authentication/
if (!sessionStorage.length) {
// Ask other tabs for session storage
localStorage.setItem('getSessionStorage', Date.now());
};
window.addEventListener('storage', function(event) {