From 4280bbcaf0af922743d4b33b1e410eee1c9bb715 Mon Sep 17 00:00:00 2001 From: Paulo Galdo Date: Thu, 23 Aug 2018 19:17:55 -0300 Subject: [PATCH] Add simple angular integration --- web/src/angular-index.ts | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 web/src/angular-index.ts diff --git a/web/src/angular-index.ts b/web/src/angular-index.ts new file mode 100644 index 0000000..fce8f77 --- /dev/null +++ b/web/src/angular-index.ts @@ -0,0 +1,43 @@ +import { AfterViewInit, Component, ElementRef, ViewChild } from '@angular/core'; +import { FormBuilder, FormGroup } from '@angular/forms'; +import Validateme from '@validate-me/core/Validateme'; +import ValidatemeField from '@validate-me/core/ValidatemeField'; +import vanillaConnector from '@validate-me/vanilla'; + +@Component({ + selector: 'angular-validateme-demo', + template: ` +
+ + +
+ ` +}) +export class AppComponent implements AfterViewInit { + + public myReactiveForm: FormGroup; + private validateme: Validateme; + @ViewChild('formHtml') formHtml: ElementRef; + + constructor(private formBuilder: FormBuilder) { + this.myReactiveForm = this.formBuilder.group({ + name: ['', []] + }); + } + + ngAfterViewInit(): void { + this.validateme = new Validateme({ + fields: [new ValidatemeField({ name: 'name' })], + }); + vanillaConnector(this.validateme, this.formHtml.nativeElement); + } + + sendForm(form: FormGroup, evt: any): void { + evt.preventDefault(); + + if (!this.validateme.validate()) { + return; + } + + } +}