Angular在尝试导航应用程序时引发错误

时间:2020-09-07 17:22:50

标签: angular error-handling

因此,我正在使用angular和laravel构建一个应用程序。 一切都很好-我已登录并关注自己的业务。 然后,我注销了,当我想重新登录我的应用程序时,不再合作了。 我在后端使用带有JWT的laravel。 我试图进入应用程序中的不同路线,例如“登录”或“注册”,但出现错误:

 ERROR Error: Uncaught (in promise): NullInjectorError: R3InjectorError(AppModule)[false -> false -> false]: 
  NullInjectorError: No provider for false!
NullInjectorError: R3InjectorError(AppModule)[false -> false -> false]: 
  NullInjectorError: No provider for false!

我的应用模块:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { NavbarComponent } from './components/navbar/navbar.component';
import { LoginComponent } from './components/login/login.component';
import { SignupComponent } from './components/signup/signup.component';
import { DashboardComponent } from './components/dashboard/dashboard.component';
import { HttpClientModule } from '@angular/common/http';
import { HttpService } from './http.service';
import { ResultsComponent } from './components/dashboard/results/results.component';
import { PricingComponent } from './components/pricing/pricing.component';

@NgModule({
  declarations: [
    AppComponent,
    NavbarComponent,
    LoginComponent,
    SignupComponent,
    DashboardComponent,
    ResultsComponent,
    PricingComponent,
  ],
  imports: [BrowserModule, AppRoutingModule, FormsModule, HttpClientModule],
  providers: [HttpService],
  bootstrap: [AppComponent],
})
export class AppModule {}

任何帮助将不胜感激!

编辑:添加HTTP服务:

    import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Injectable({
  providedIn: 'root',
})
export class HttpService {
  constructor(private http: HttpClient) {}
  private baseUrl = 'http://localhost:8000/api';
  login(form) {
    return this.http.post(`${this.baseUrl}/login`, form);
  }
  signup(form) {
    return this.http.post(`${this.baseUrl}/signup`, form);
  }
  findVehicle(vehicleNumber = 'empty') {
    return this.http.get(`${this.baseUrl}/findVehicle/${vehicleNumber}`);
  }
  getPricing(year) {
    return this.http.get(`${this.baseUrl}/get-pricing/${year}`);
  }
}

1 个答案:

答案 0 :(得分:0)

答案发现 因此事实证明您不能使用!作为提供者。 我用过

    canActivate: [!AfterLoginService],

这就是问题所在。