An issue has occurred: Uncaught (in promise): NullInjectorError: R3InjectorError(AppModule)[NavbarComponent -> NavbarComponent

I've been working on implementing Google Auth login with Firebase, but I keep encountering an issue when trying to load another component or page after logging in. I've spent the entire day trying to debug this problem and it's really frustrating. Any help would be greatly appreciated.

You can view my entire project publicly at https://github.com/domilx/ProjetBocal-Angular

ERROR Error: Uncaught (in promise): NullInjectorError: R3InjectorError(AppModule)[NavbarComponent -> NavbarComponent -> NavbarComponent]: 
  NullInjectorError: No provider for NavbarComponent!
get@http://localhost:4200/vendor.js:120414:27

Sample Code:

Navbar.component.html:

<div mat-elevation-z4>
  <mat-toolbar color="primary">
    <button routerLink="dashboard" mat-button aria-label="Home">
      <mat-icon>home</mat-icon>
      Projet Bocal
    </button>

    <span class="spacer-1"></span>

    <button mat-button aria-label="Classroom">
      <mat-icon>class</mat-icon>
      Classroom
    </button>

    <button mat-button aria-label="Links">
      <mat-icon>links</mat-icon>
      Links
    </button>

    <span class="spacer-1"></span>

    <button mat-button aria-label="Logout" *ngIf="auth.user$ | async as user" (click)="auth.signOut()">
      <mat-icon>exit_to_app</mat-icon>
      Logout, {{ user.displayName }}
    </button>
    <span class="spacer"></span>

    <button routerLink="settings" mat-icon-button aria-label="settings" *ngIf="auth.user$ | async as user">
      <mat-icon>settings</mat-icon>
    </button>

  </mat-toolbar>
</div>

Auth.service.ts

// Code sample for Auth service
... (rest of the code)

}

Auth.guard.ts

// Code sample for Auth guard
... (rest of the code)

App.module.ts

// Code sample for App module
... (rest of the code)

App-routing.module.ts

// Code sample for App routing module
... (rest of the code)

navbar.component.ts

// Code sample for navbar component
... (rest of the code)

Answer №1

After some investigation, I pinpointed the problem. It turns out that in my dashboard.component.ts file, I had previously imported the NavBar for testing purposes but forgot to remove it:

import { NavbarComponent } from './../../../shared/navbar/navbar.component';
import { Component, OnInit,EventEmitter,Output } from '@angular/core';
import { RouterModule } from '@angular/router';
import { AuthService } from '../../../../services/auth.service';

@Component({
  selector: 'app-dashboard',
  templateUrl: './dashboard.component.html',
  styleUrls: ['./dashboard.component.css']
})
export class DashboardComponent implements OnInit {

  @Output() isLogout = new EventEmitter<void>()
  constructor(NavbarComponent : NavbarComponent, public auth: AuthService) { }


  ngOnInit(): void {

  }

}

All I had to do was simply remove this line:

NavbarComponent : NavbarComponent

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

Is there a marble experiment that will alter its results when a function is executed?

Within Angular 8, there exists a service that contains a readonly Observable property. This property is created from a BehaviorSubject<string> which holds a string describing the current state of the service. Additionally, the service includes method ...

Adding a constant to a Vue component

Currently working on developing an application using Vue and TypeScript. I'm focused on refactoring some aspects, particularly moving hard-coded strings from a template to a separate constant. What has been implemented is as follows: export const va ...

Angular 7 ERROR: The SystemJS reference is missing

In the process of developing an Angular 7 project with systemjs for dynamic module loading, I encountered an issue. Upon attempting to utilize it, I encountered the following error: ERROR ReferenceError: SystemJS is not defined Within my package.json f ...

Exploring Angular Material's Autocomplete feature and staying updated with incoming data changes

https://material.angular.io/components/autocomplete/examples export class AutocompleteAutoActiveFirstOptionExample implements OnInit { myControl = new FormControl(); options: string[] = ['One', 'Two', 'Three']; filtered ...

Attempting to access a specific JSON key using Observables

Apologies for the question, but I'm relatively new to Typescript and Ionic, and I find myself a bit lost on how to proceed. I have a JSON file containing 150 entries that follow a quite simple interface declaration: export interface ReverseWords { id ...

Setting a border on a specific column in ag-grid is a simple task that can help you customize

I have a table where the first set of columns differs from the rest. I am looking to emphasize this distinction by adding a vertical border on the right side of the specific column to highlight it both in the header and rows. Our setup includes using the ...

When I attempt to translate R.string in FragmentPagerAdapter, an unusual number suddenly pops up before me

Struggling to insert a text translation into a FragmentPagerAdapter, I've tried various methods like using return (R.string.Chats) + ""; An unusual occurrence for me is the appearance of a strange number in three tabs. Image: https://i.sst ...

Using async await with Angular's http get

In my service component, I have the following code snippet that retrieves data from an API: async getIngredientsByProductSubCategory(productSubCategoryId: number) { const url = '/my-url'; let dataToReturn: any; await this.http.get(ur ...

Automatically generate *.story.ts files when using the Angular CLI to create a component

I'm exploring the possibility of implementing Storybook in my Angular project. My aim is to automatically generate a story file for each component, as manually creating them can be tedious. Therefore, I am looking into ways to automate the generation ...

What is the process for installing both highcharts-angular and highcharts together?

UPDATE: Issue resolved - the problem was that the package.json file was read-only (refer to my answer). I have an Angular application (version 7) and I am attempting to integrate Highcharts. I am following the guidelines provided by highcharts-angular her ...

TypeScript introduces a new `prop` method that handles missing keys in objects

Is there a way to create a prop function that can return a default type if the specified key is not found in object o? type Prop = <K, O extends {}>(k: K, o: O) => K extends keyof O ? O[K] : 'Nah'; /* Argument of type 'K ...

Mastering the Type Model on Firestore Function to Retrieve Field ValuesUnlock the potential of the Type

When retrieving data from Firestore, I am able to print the entire object using doc.data. However, I am having trouble accessing the specific value of unixtime as it is coming through as undefined. I need help in correctly applying my type model so that I ...

Troubleshooting: Angular Firebase's signInWithRedirect() and getRedirectResult() functions are experiencing technical difficulties

Within my AuthService, I have implemented a function for signing in with Google which, depending on the user's device, initiates the sign-in process either with a redirect or a pop-up. The pop-up sign-in functionality is operating smoothly, however, ...

Quote the first field when parsing a CSV

Attempting to utilize Papaparse with a large CSV file that is tab delimited The code snippet appears as follows: const fs = require('fs'); const papa = require('papaparse'); const csvFile = fs.createReadStream('mylargefile.csv&apo ...

Sending data from parent component to change MUI Button color (React with typescript)

Recently, I've been integrating MUI (v5) into a create-React-App with typescript. I have a custom theme set up as well. My goal is to develop a MyButton Component that accepts a buttonType prop (of type string), which corresponds to my theme.palette, ...

In TypeScript, develop a specialized Unwrap<T> utility type

After successfully creating a helper type to unwrap the inner type of an Observable<T>, I began wondering how to make this type completely generic. I wanted it to apply to any type, not just Observable, essentially creating Unwrap<T>. Here is ...

Combining Interfaces in Typescript: Utilizing Union Types with a Base and Extended Interface

I'm facing an issue with the following code snippet interface BaseA { a: number; } interface SpecialA extends BaseA { b: number; } type A = BaseA | SpecialA const a = { a: 5, b: 5 } as A console.log(a.b) Even though I thought the code was ...

An issue occurred while loading: Uncaught ReferenceError: module is missing from the http://localhost:9876/_karma_webpack_/scripts.js file on line 1

Error image I encountered an error while performing jasmine karma unit testing with angular. Can anyone provide assistance on this issue? Here is my karma.conf.js file: // Karma configuration file, see link for more information //<br> https://karma ...

Finding a date from a calendar with a readonly property in Playwright

Just starting out with the playwright framework after working with Protractor before. I'm trying to figure out the correct method for selecting a date in Playwright. selector.selectDate(date) //having trouble with this ...

Tips for retrieving and storing an HTTP Post response in Angular 4 using HTML formatting

I am currently facing a challenge in Angular 4 where I am trying to retrieve and read the HTTP Post response. However, I am unable to do so because the response is in HTML format. Despite my efforts of researching various sources, I have not been able to f ...