problem with mat-progress-bar, BehaviorSubject is malfunctioning

I can't seem to identify the issue :(

The concern lies in the fact that isLoadingLogin is consistently set to false, preventing the mat progress bar from being shown.

My implementation of LoginFormComponent appears as follows:

template: `
    {{(isLoadingLogin | async) | json }}
    <mat-progress-bar *ngIf="(isLoadingLogin | async)" mode="indeterminate" class="progress-bar"></mat-progress-bar>
  `,
  styleUrls: ['./login-form.component.scss']
})
export class LoginFormComponent implements OnInit, OnDestroy {
  isLoadingLogin: Observable<boolean>;

  ngOnInit() {
    this.isLoadingLogin = this.userService.isLoading;
  }

  login() {
    if (this.form.valid) {
      const email = this.form.get('email').value;
      const password = this.form.get('password').value;
      this.sessionService.login(email, password);
    }
  }
}

Furthermore, the accompanying services are as follows:

@Injectable({
  providedIn: 'root'
})
export class SessionService {

  login(email: string, password: string) {
    this.authService.login(email, password).subscribe(token => {
      this.loginUser(token);
    });
  }
}
@Injectable({
  providedIn: 'root'
})
export class AuthService {

  login(email: string, password: string) {
    return this.userService.login(email, password).pipe(map(({token}: any) => this.storeToken(token)));
  }
}
@Injectable()
export class UserService {
  private isLoadingLogin: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
  isLoading: Observable<boolean> = this.isLoadingLogin.asObservable();

  login(user, password) {
    this.isLoadingLogin.next(true);
    console.log(this.isLoadingLogin.value);
    return this.http.post(this.loginUrl, JSON.stringify({
      user,
      password
    }), this.httpOptions)
      .pipe(
        catchError(error => this.errorHandleService.handleError('login', error)),
        finalize(() => {
          this.isLoadingLogin.next(false);
          console.log(this.isLoadingLogin.value);
        })
      );
  }
}

On a side note, I have verified the correct import of UserService within @NgModule.

Answer №1

Issue Resolved:

@Injectable({ providedIn: 'root' })
export class UserService { }

Make sure to exclude it from the providers list in my module.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to set HTML content in the ElementRef's nativeElement?

I am trying to use a directive to set the content of an HTML element. export class AdvertisementDirective { constructor(el: ElementRef) { el.nativeElement.style.background = 'yellow'; el.nativeElement.content = '<p>Hello Wo ...

There seems to be an issue with the subscription of a subject between two modules in Angular 5

Currently, I am in the process of developing a project using Angular 5. One requirement is to display an app loading spinner frequently. To achieve this, I have created a shared module along with a spinner component within it. Below is the content of my mo ...

Error: Unable to perform operation on undefined object when trying to map over 'reminder' object

I've been struggling with my reminder-list.tsx file. No matter how many times I try to fix it, I always end up failing. Can someone help me figure out how to resolve this issue? Every time I run the code, I get the TypeError: undefined is not an obje ...

Having trouble getting tsserver-plugins to function properly in either Atom or VSC

My team and I are on a mission to enhance our Angular 2 templates with code completion, similar to what is showcased in this gif. To achieve this goal, we require: tsserver-plugins coupled with tslint-language-service and @angular/language-service We ...

Encountering issues with the functionality of async await

I am a beginner when it comes to utilizing the async, await, and promise features in JavaScript. My current focus is on: async function sendTextMessage(text) { console.log("----1----"); var messageData = { message: { text: tex ...

Is it possible in Angular Typescript to map the attributes of an array to a class object or generate a new object using the elements of the array?

Here are the specifications of the tools I am currently using: Angular CLI: 10.0.6 Node: 12.18.2 Operating System: win32 x6 Angular Version: 10.0.10 My goal is to retrieve selected rows from ag-grid using a specific method. When I retrieve the row, i ...

A guide to successfully transferring textarea content to the clipboard in an Angular application

I'm struggling with a task in an Angular 7 application where I have a textarea and need to copy its content to the clipboard when a button is clicked. I've implemented the following code in the button's click handler: if (this.txtConfigFile ...

Challenges arise when attempting to merge declarations in Typescript involving passport, passport-local, and express-session

I'm currently facing challenges trying to integrate passport, passport-local, and express-session with Typescript. After installing all four necessary libraries - @types/passport, @types/express-session @types/passport-local, and @types/express - I in ...

Issue encountered while executing the Docker run command: EEXIST - The file already exists as a symbolic link from '/app/node_modules' to '/app/.build/node_modules'

I've encountered an issue while trying to run a Node.js TypeScript app with Docker. The Dockerfile I'm using builds the image successfully: FROM lambci/lambda:build-nodejs6.10 # Set up the app directory WORKDIR /app # Install app dependencies ...

Testing Angular application with a currency pipe results in an error stating "currency

Utilizing the built-in angular currency pipe in my components works perfectly fine. However, when attempting to unit test my component, an error occurs: https://i.stack.imgur.com/J18JL.png I am using Angular 10 with Ivy and have imported the CommonModule, ...

In Angular 6, triggering a reset on a reactive form will activate all necessary validators

As a beginner in angular 6, I am currently facing an issue with resetting a form after submitting data. Although everything seems to be functioning properly, when I reset the form after successfully submitting data to the database, it triggers all the req ...

"Using an indexer in TypeScript allows for direct access to object properties by simply specifying the key within

I have a requirement to access an object property using a string as the key interface MyObject { prop1: string; prop2: string; prop3: string; prop4: string; prop5: string; } let initialValues: MyObject; //I initialize some properties initialVa ...

What is the best way to implement a custom layout with nuxt-property-decorator?

Summary of Different Header Components in Nuxt In order to set a different header component for a specific page in Nuxt, you can create separate layout files. layout ├ default.vue // <- common header └ custom.vue // <- special header for s ...

The absence of transpiled Typescript code "*.js" in imports

Here is an example of the code I am working with: User.ts ... import { UserFavoriteRoom } from "./UserFavoriteRoom.js"; import { Room } from "./Room.js"; import { Reservation } from "./Reservation.js"; import { Message } from ...

Is there a way for me to loop through an object without prior knowledge of its keys?

Upon receiving data from the server, it looks something like this: { "2021-10-13": { "1. open": "141.2350", "2. high": "141.4000", "3. low": "139.2000", "4. close& ...

Loading Angular 4 Material Tabs when a tab is selected

Can lazy loading be implemented with Angular Material Tabs? If not, I am looking for a solution to execute a method when switching tabs. ...

What is the process for unsubscribing from a Firebase list in Angular2?

My code is set up to connect to a Firebase list by using the following: tasks: FirebaseListObservable<ITask[]>; constructor(private af: AngularFire) { this.tasks = this.af.database.list("/tasks"); } However, I am now facing an issue where I need ...

A Unique Identifier in Kotlin

In my typescript class, I have a member that accepts any as the name: interface ControlTagType { type?: String | null; [name: string]: any } class ControlTag { tagSource: String | null = null; tag: ControlTagType | null = null; } expor ...

Angular neglects the specified animation timing

I created a sidebar component that relies on the sidebarExpanded state passed through Input(). Despite the correct animation trigger upon input change, the width adjustment happens abruptly. Interestingly, the same animation code works flawlessly in anothe ...

Array of generic types in Typescript

Here's a method that I have: getFiveObjectsFromArray(array: T[]) { return array.slice(0, 5); } I've been using this method multiple times. Is there a way in TypeScript to pass a generic argument instead of using multiple types? Also, when ...