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
validateUniqueEmailObservable( email : string ) { | |
return new Observable(observer => { | |
if( email === "alreadyExistsEmail@gmail.com" ) { | |
observer.next({asyncInvalid: true}); | |
} else { | |
observer.next(null); | |
} | |
}); | |
} |
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
validate( c : AbstractControl ) { | |
return this.validateUniqueEmailObservable(c.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
validate( c : AbstractControl ) { | |
return this.validateUniqueEmailObservable(c.value).first(); | |
} |
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
validate( c : AbstractControl ) { | |
return this.validateUniqueEmailObservable(c.value).debounceTime(500).distinctUntilChange().first(); | |
} |
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 { ViewChild } from "@angular/core/src/metadata/di"; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: '<input type="text" #input>' | |
}) | |
export class AppComponent { | |
@ViewChild("input") input; | |
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 { Directive, Renderer, ElementRef } from '@angular/core'; | |
@Directive({ | |
selector: '[exploreRenderer]' | |
}) | |
export class ExploreRendererDirective { | |
private nativeElement : Node; | |
constructor( private renderer : Renderer, private element : ElementRef ) { | |
this.nativeElement = element.nativeElement; | |
} | |
} |
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
ngAfterContentInit() { | |
let inputElement = this.renderer.createElement(this.nativeElement, "input"); | |
this.renderer.setElementAttribute(inputElement, "value", "Hello from renderer"); | |
this.renderer.invokeElementMethod(inputElement, "focus", []); | |
} |
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
ngAfterContentInit() { | |
let buttonElement = this.renderer.createElement(this.nativeElement, "button"); | |
this.renderer.createText(buttonElement, "Click me!"); | |
this.renderer.setElementProperty(buttonElement, "disabled", true); | |
this.renderer.listen(buttonElement, "click", ( event ) => console.log(event)); | |
this.renderer.setElementClass(buttonElement, "btn-large", true); | |
this.renderer.setElementStyle(buttonElement, "backgroundColor", "yellow"); | |
} |
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
let input = document.querySelector('input[type="text"]'); | |
let button = document.querySelector('button'); | |
let h1 = document.querySelector('h1'); | |
button.addEventListener('click', () => { | |
emitter.emit('event:name-changed', {name: input.value}); | |
}); | |
let emitter = new EventEmitter(); | |
emitter.subscribe('event:name-changed', data => { |
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
class EventEmitter { | |
constructor() { | |
this.events = {}; | |
} | |
} |