【问题标题】:Angular throws an error while trying to navigate the appAngular 在尝试导航应用程序时抛出错误
【发布时间】:2020-09-07 17:22:50
【问题描述】:

所以我正在用 angular 和 laravel 构建一个应用程序。 一切都运行良好——我已经登录并专注于我自己的事情。 然后,我退出了,当我想重新登录我的应用程序时,我不再合作了.. 我在后端使用 laravel 和 JWT。 我试图去应用程序中的不同路线,如登录或注册,但我收到错误:

 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}`);
  }
}

【问题讨论】:

  • 这里没有足够的信息,但我怀疑问题可能出在 HttpService..
  • 是的,请添加更多信息
  • 我已经添加了。请随意查看

标签: angular error-handling


【解决方案1】:

找到答案 所以事实证明你不能使用 a !作为提供者。 我用过

    canActivate: [!AfterLoginService],

这就是问题所在。

【讨论】:

    猜你喜欢
    • 2015-01-02
    • 2019-04-02
    • 2022-07-30
    • 2019-01-01
    • 2012-12-28
    • 2019-04-22
    • 2018-11-01
    • 2020-06-18
    • 1970-01-01
    相关资源
    最近更新 更多