Skip to content

Instantly share code, notes, and snippets.

View NetanelBasal's full-sized avatar
🎯
Focusing

Netanel Basal NetanelBasal

🎯
Focusing
View GitHub Profile
class Person {
@storage() public name: string;
@storage('sur', 'session') public surname: string;
constructor(name : string, surname : string) {
this.name = name;
this.surname = surname;
}
@NetanelBasal
NetanelBasal / navigation.component.ts
Created October 20, 2016 15:02
navigation.component.ts
import { select } from 'ng2-redux';
@Component({
template: '
<nav>
<ul>
<li *ngIf="!(isLoggedIn$ | async)">Sign in</li>
<li *ngIf="!(isLoggedIn$ | async)">Sign up</li>
<li *ngIf="(isLoggedIn$ | async)">Log out</li>
</ul>
</nav>
@NetanelBasal
NetanelBasal / showIfLoggedIn.directive.ts
Last active January 17, 2017 16:05
showIfLoggedIn.directive.ts
import { Directive, Input } from '@angular/core';
import { TemplateRef, ViewContainerRef } from '@angular/core';
import { select } from "ng2-redux";
import { Observable } from "rxjs";
@Directive({selector: '[showIfLoggedIn]'})
export class ShowIfLoggedInDirective {
subscription;
@Input('showIfLoggedIn') renderTemplate;
<p *ngIf="condition">
Hello, world!
</p>
That turns into this:
<template [ngIf]="condition">
<p>
Hello, world!
</p>
</template>
@NetanelBasal
NetanelBasal / a.html
Last active October 20, 2016 15:12
a
<monster-details *showIfLoggedIn="true"></monster-details>
<nav>
<ul>
<li *showIfLoggedIn="false">Sign in</li>
<li *showIfLoggedIn="false">Sign up</li>
<li *showIfLoggedIn="true">Log out</li>
</ul>
</nav>
import { Directive, forwardRef } from "@angular/core";
import { NG_ASYNC_VALIDATORS, Validator, AbstractControl } from "@angular/forms";
import { Observable } from "rxjs";
@Directive({
selector: "[asyncValidator][formControlName], [asyncValidator][ngModel]",
providers: [
{
provide: NG_ASYNC_VALIDATORS,
useExisting: forwardRef(() => AsyncValidator), multi: true
}
export default class AsyncValidator implements Validator {
}
validate( c : AbstractControl ) : Promise<{[key : string] : any}>|Observable<{[key : string] : any}> {
}
validateUniqueEmailPromise( email : string ) {
return new Promise(resolve => {
setTimeout(() => {
if( email === "alreadyExistsEmail@gmail.com" ) {
resolve({
asyncInvalid: true
})
} else {
resolve(null);
}
validate( c : AbstractControl ) {
return this.validateUniqueEmailPromise(c.value);
}