Last active
June 11, 2018 09:03
-
-
Save alanxone/abff3241c4eba11c43abdb82db7446d2 to your computer and use it in GitHub Desktop.
NGRX Tutorial - Auth Component
This file contains hidden or 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
// 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