Skip to content

Instantly share code, notes, and snippets.

View alexonozor's full-sized avatar
🏠
Working from home

Alex Onozor alexonozor

🏠
Working from home
View GitHub Profile
This file has been truncated, but you can view the full file.
{
"biodata": [
{
"JambRegNo": "011/02/CSC/1034",
"MatricNo": "011/02/CSC/1034",
"Title": "Mr",
"Surname": "Abdallah",
"FirstName": "Maryam",
"MiddleName": "",
"MaritalStatus": "",
@alexonozor
alexonozor / flatten.js
Created October 7, 2016 10:51
Xample method for Array#flatten
function flatten(arr) {
return arr.reduce(function (flat, toFlatten) {
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
}, []);
}
import { FormControl } from ‘@angular/forms’;
export class UserComponent { 
userName = new FormControl(); 
}
<label class="center-block">userName:
<input class="form-control" [formControl]="userName">
</label>
import { FormControl, FormGroup } from '@angular/forms'; // notice we also import FormGroup
export class UsersComponent {
userForm = new FormGroup ({
userName: new FormControl()
});
}
<form [formGroup]="userForm" novalidate>
<div class="form-group">
<label class="center-block">userName:
<input class="form-control" formControlName="userName">
</label>
</div>
</form>
const userForm = new FormGroup({
userName: new FormControl(''),
firstName: new FormControl(''),
lastName: new FormControl(''),
address: new FormGroup({
street: new FormControl(''),
city: new FormControl(''),
zipCode: new FormControl('')
})
});
<div formGroupName="address" class="well well-lg">
<div class="form-group">
<label class="center-block">Street:
<input class="form-control" formControlName="street">
</label>
</div>
<div class="form-group">
<label class="center-block">City:
<input class="form-control" formControlName="city">
</label>
<p>UserName value: {{ userForm.get('userName').value }}</p>
//Get the street of the nested address
<p>Street value: {{ userForm.get('address.street').value}}</p>
/** A user name can't match the given regular expression */
export function forbiddenUserNameValidator(nameRe: RegExp): ValidatorFn {
return (control: AbstractControl): {[key: string]: any} => {
const forbidden = nameRe.test(control.value);
return forbidden ? {'forbiddenName': {value: control.value}} : null;
};
}