Skip to content

Instantly share code, notes, and snippets.

import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { map, switchMap } from 'rxjs/operators';
import { doLogin, setLoginStateSuccess, setErrorMessage } from './login.action';
import { LoginService } from '../../services/login/login.service';
@Injectable()
export class LoginEffects {
setLoginStateSuccess$ = createEffect(() =>
import { createReducer, on } from '@ngrx/store';
import { setLoginStateSuccess, setErrorMessage } from '../login/login.action';
// ↑↑↑このactionを追加
export interface LoginModel {
isLogin: boolean;
errorMessage?: string;
}
export const initialState: LoginModel = { isLogin: false };
import { createAction, props } from '@ngrx/store';
// ログインするときのactionです、ログインID、パスワードをactionの引数に持ちたい時の書き方
// '[Login] Do Login'は、'[どの画面]どんな処理'のようなイメージです
export const doLogin = createAction(
'[Login] Do Login',
props<{ loginId: string, password: string }>()
);
// storeのisLoginを更新したい時。更新したい値を引数にする
import { createSelector, createFeatureSelector } from '@ngrx/store';
// <{ isLogin: boolean, errorMessage: string }>はstoreの型、reducerに書いたやつ
// 'LoginState'はキー。好きな名前でOK
export const selectFeature = createFeatureSelector<{ isLogin: boolean, errorMessage: string }>('LoginState');
// getIsLoginというselectorを作成し、storeからisLoginを取得
export const getIsLogin = createSelector(
selectFeature,
(state) => state.isLogin
export interface LoginModel {
isLogin: boolean;
errorMessage?: string;
}
export const initialState: LoginModel = { isLogin: false };
yarn add @reduxjs/toolkit
yarn add redux
yarn add @ngrx/store-devtools
ionic capacitor copy ios
ionic capacitor open ios
npm install -g ios-sim
brew install ios-deploy
cd ionic-first-app
ionic serve