Skip to content

Commit

Permalink
Step 19.23: Added the signup component
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha committed Nov 27, 2016
1 parent 6092476 commit 826068c
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions client/imports/app/auth/signup.component.ts
@@ -0,0 +1,43 @@
import {Component, OnInit, NgZone} from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { Accounts } from 'meteor/accounts-base';

import template from './signup.component.html';

@Component({
selector: 'signup',
template
})
export class SignupComponent implements OnInit {
signupForm: FormGroup;
error: string;

constructor(private router: Router, private zone: NgZone, private formBuilder: FormBuilder) {}

ngOnInit() {
this.signupForm = this.formBuilder.group({
email: ['', Validators.required],
password: ['', Validators.required]
});

this.error = '';
}

signup() {
if (this.signupForm.valid) {
Accounts.createUser({
email: this.signupForm.value.email,
password: this.signupForm.value.password
}, (err) => {
if (err) {
this.zone.run(() => {
this.error = err;
});
} else {
this.router.navigate(['/']);
}
});
}
}
}

0 comments on commit 826068c

Please sign in to comment.