Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export class AuthenticatetokenComponent implements OnInit {
- constructor(private authService: AuthService,private spinner: NgxSpinnerService) {}
- public showSpinner() {
- this.spinner.show();
- }
- public stopSpinner() {
- this.spinner.hide();
- }
- private postToken() {
- this.authService.postToken(this.token);
- }
- }
- @Injectable()
- export class AuthService {
- private BASE_URL: string = "http://localhost:8080";
- constructor(private authenticateToken: AuthenticatetokenComponent, private _router: Router, private _dataservice: DataService) { }
- postToken(token: string) : void {
- this.authenticateToken.showSpinner();
- if(this.authenticateToken.token == '') {
- this.authenticateToken.stopSpinner();
- this.authenticateToken.openModal("Tokenveld is leeg! Voer aub een token in!");
- }
- this.authenticateToken.httpClient.post('/authentication', {
- token: token
- }
- ).subscribe(
- (data: any) => {
- if (token === '') {
- this.authenticateToken.stopSpinner();
- console.log('Khiem hier error in duwen');
- throw new Error('This token is not valid');
- } else {
- this.authenticateToken.elementRef.nativeElement.ownerDocument.body.style.backgroundColor = 'white';
- this._dataservice.electionFromService = data;
- this._dataservice.tokenFromService = token;
- this.authenticateToken.stopSpinner();
- this._router.navigateByUrl('/voting-page');
- }
- }
- );
- }
- getRestCall() : void {
- this.authenticateToken.httpClient.get('http://localhost:8080/test')
- .subscribe(
- (data: any[]) => {
- this.authenticateToken.data = data;
- console.log(data);
- }
- );
- }
- }
Add Comment
Please, Sign In to add comment