I am trying to create a login form. Could anyone please suggest me how to add Remember me Functionality to the login page in Angular application?.....Your help is greatly appreciated!.. Thank you in advance! My login.ts file is as below,
ngOnInit() {
this.form = this.formBuilder.group({
email: ['', [Validators.required, Validators.email] ],
password: ['', Validators.required]
});
}
get f(){
return this.form.controls;
}
onSubmit() {
this.submitted = true;
this.accountService.login(this.f.email.value, this.f.password.value)
}
and account.service.ts file is as below,
export class AccountService {
private accountSubject: BehaviorSubject<Account>;
public account: Observable<Account>;
constructor(
private router: Router,
private http: HttpClient
) {
this.accountSubject = new BehaviorSubject<Account>(null);
this.account = this.accountSubject.asObservable();
}
public get accountValue(): Account {
return this.accountSubject.value;
}
login(email: string, password: string) {
return this.http.post<any>(`${baseUrl}/authenticate`, { email, password }, { withCredentials: true })
.pipe(map(account => {
this.accountSubject.next(account);
return account;
}));
}
logout() {
this.http.post<any>(`${baseUrl}/revoke-token`, {}, { withCredentials: true }).subscribe();
this.accountSubject.next(null);
this.router.navigate(['/account/login']);
}
}