mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
Added a toast service error to show error messages on the screen isntead of using console.log
This commit is contained in:
@@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { AuthService } from 'src/app/services/auth.service';
|
||||
import { User } from 'src/app/models/user.model';
|
||||
import { ToastService } from 'src/app/services/toast.service';
|
||||
|
||||
|
||||
@Component({
|
||||
@@ -18,7 +19,8 @@ export class LoginPage implements OnInit {
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
private authService: AuthService) { }
|
||||
private authService: AuthService,
|
||||
private toastService: ToastService) { }
|
||||
|
||||
ngOnInit() {
|
||||
|
||||
@@ -47,11 +49,11 @@ export class LoginPage implements OnInit {
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log("Não foi possível fazer login");
|
||||
this.toastService.presentToast('Não foi possível fazer login"');
|
||||
}
|
||||
}
|
||||
else{
|
||||
console.log("Preencha todos campos");
|
||||
this.toastService.presentToast('Preencha todos campos');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ToastService } from './toast.service';
|
||||
|
||||
describe('ToastService', () => {
|
||||
let service: ToastService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(ToastService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ToastController } from '@ionic/angular';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ToastService {
|
||||
|
||||
constructor(public toastController: ToastController) { }
|
||||
|
||||
async presentToast(infoMessage: string) {
|
||||
const toast = await this.toastController.create({
|
||||
message: infoMessage,
|
||||
duration: 2000
|
||||
});
|
||||
toast.present();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user