angular - Angular 在尝试导航应用程序时抛出错误
问题描述
所以我正在用 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}`);
}
}
解决方案
ANSWER FOUND 所以事实证明你不能使用 ! 作为提供者。我用过
canActivate: [!AfterLoginService],
这就是问题所在。
推荐阅读
- excel - 将 Excel 宏输出限制为包含内容的单元格
- kubernetes - 从 kubernetes 中的环境变量创建 tls secret
- python - 基本 Python 代码:将短语转换为相应的首字母缩略词
- azure - 本地计算机和 Azure 上的虚拟机之间的文件共享
- sql - SQL 查询将列转换为行
- java - 如何打破消费者循环
- mysql - Error for invalid floating-point numbers in MySQL
- azure-blob-storage - Azure Bot Framework composer - ways to save conversation to Blob storage
- ios - React-native, cant run project. Error: 'GoogleUtilities/GULLoggerLevel.h' file not found
- c# - Nuget - Is there a way to conditionally add files if the consumer is a web or desktop application (.NET)?