【发布时间】:2020-06-08 07:06:11
【问题描述】:
我正在运行我的应用程序LiveCicle,当我导航到地图路线时出现此错误:
ERROR Error: Uncaught (in promise): TypeError: _angular_core__WEBPACK_IMPORTED_MODULE_1__.ɵɵdefineInjectable is not a function
TypeError: _angular_core__WEBPACK_IMPORTED_MODULE_1__.ɵɵdefineInjectable is not a function
at tm.service.ts:9
这很奇怪,因为我将 tm 服务定义为路由模块中的提供者。
@NgModule({
providers: [
{
provide:
HTTP_INTERCEPTORS
,
useClass: AuthInterceptor,
multi: true
},
TicketMasterService
],
})
const routes: Routes = [
{path: 'map', loadChildren: () => import('./event-map-page/event-map-page.module').then(m => m.EventMapPageModule)},
{path: '**', redirectTo: '', pathMatch: 'full'},
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
我只在生产中遇到此错误。当我在本地运行时,一切正常。
import { Injectable, OnInit } from '@angular/core';
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
import { environment } from '../../environments/environment';
import { DataService } from '../../services/dataService/data.service';
import { TmEvent } from '../../models/tmEvent/tm-event.model';
@Injectable()
export class TicketMasterService {
noAuthHeader = { headers: new HttpHeaders({ 'NoAuth': 'True'})};
private readonly TM_EVENTS = 'TM_EVENTS';
tmEvents: any = [];
constructor(private http: HttpClient, private data: DataService) {
}
fetchTmData() {
this.http.get(environment.apiBaseUrl + '/ticketmaster-events', this.noAuthHeader).subscribe(res => {
this.getTheFields(res);
});
}
}
【问题讨论】:
-
你能粘贴 TicketMasterService 吗?
-
@Nosheep 已粘贴
-
remove providedIn: 'platform',因为您已经在模块级别拥有此服务作为提供者,反之亦然。
-
@Nosheep 仍然出现相同的错误...我还注意到,当您单击路线两次时,您会收到此错误
core.js:4117 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'ɵmod' of undefined TypeError: Cannot read property 'ɵmod' of undefined at getNgModuleDef (core.js:1880) -
尝试完全删除 Injectable()。
标签: angular typescript webpack lazy-loading