Skip to content

Instantly share code, notes, and snippets.

@alanxone
Last active June 11, 2018 09:03
Show Gist options
  • Save alanxone/abff3241c4eba11c43abdb82db7446d2 to your computer and use it in GitHub Desktop.
Save alanxone/abff3241c4eba11c43abdb82db7446d2 to your computer and use it in GitHub Desktop.
NGRX Tutorial - Auth Component
// NGRX Complete Tutorial Without Pain (Angular6 / RxJS6)
// https://medium.com/@andrew.kao/ngrx-complete-tutorial-without-pain-angular6-rxjs6-5511b8cb8dac
import { Component, OnInit } from '@angular/core';
import { Authentication } from '(authentication model)';
import * as fromTeam from '(team main reducers)';
import * as Auth from '(auth actions)';
import { Store, select } from '@ngrx/store';
// "Permission" has the similiar logic, try it.
@Component({
selector: 'component-auth',
templateUrl: 'the-auth-form.component.html'
})
export class AuthComponent implements OnInit {
// The risky obserable object might be used to show some msg in template
risky$ = this.store.pipe(select(fromTeam.getAuthRisk));
constructor(private store: Store<fromTeam.TeamState>) {}
ngOnInit() {}
// The form is submitted with the corresponding model type `Authentication`
onSubmit($event: Authentication) {
this.store.dispatch(new Auth.Login($event));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment