Uncaught TypeError:无法读取registerNgModuleType-Angular 9中未定义的属性'id',>

问题描述 投票:0回答:1
我遇到了一个又一个的bug,一个又一个的修复,直到我似乎不了解为止。该应用程序已编译,但主页为空,并且错误:core.js:36236 Uncaught TypeError: Cannot read property 'id' of undefined at registerNgModuleType

数据服务

@Injectable({ -> some say it isnt needed but i ran into other issue... providedIn: 'root' }) export class DataService { constructor(@Inject(String) private url: string, private http: HttpClient){} public getAll(): Observable<any> { return this.http.get<any>(this.url); } }

home组件中的调用(请保留forkjoin,暂时保持简单)] >>

categories: any[]; products: any[]=[]; filteredProducts: any[]=[]; category: string; constructor( private route: ActivatedRoute, private dataService: DataService ) { this.dataService.getAll().subscribe(data=>{ this.categories=data[0]['categories']; console.log(this.categories) }) this.dataService.getAll().subscribe(data=>{ this.products=data[0]['products']; console.log(this.products) })

类别服务(产品相同)

@Injectable({ providedIn: 'root' }) export class CategoriesService extends DataService { constructor(http: HttpClient) { super('assets/categories.json', http) } }

而且我在Angular.JSON中也有"aot": false,

EDIT2:应用。 module.ts

import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; import { HomeComponent } from './components/home/home.component'; import { HttpClient, HttpClientModule } from '@angular/common/http'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { DataService } from './services/data.service'; import { CategoriesService } from './services/categories.service'; import { ProductsService } from './services/products.service'; @NgModule({ declarations: [ AppComponent, HomeComponent ], imports: [ BrowserModule, HttpClientModule, AppRoutingModule, BrowserAnimationsModule, ], providers: [HttpClient, DataService, CategoriesService, ProductsService], bootstrap: [AppComponent] }) export class AppModule { }

更新后的错误:)

Uncaught (in promise): NullInjectorError: R3InjectorError(AppModule)[DataService -> String -> String -> String]: NullInjectorError: No provider for String!

编辑3:现在我有一个正在运行的stackblitz,但是没有我想要的父服务或类继承。该代码也属于@Michael D

我遇到了一个又一个的bug,一个又一个的修复,直到我似乎不了解为止。该应用程序已编译,但主页为空,错误为:core.js:36236 Uncaught TypeError:...

angular build aot
1个回答
0
投票
您在providers阵列中有模块,所以不能放置模块(使用imports)。

imports数组内的服务相同(仅导入模块的模块),这是提供错误的原因。

© www.soinside.com 2019 - 2024. All rights reserved.