在我的角度应用程序中,当我浏览主页到延迟加载的模块时,我的应用程序模块中的延迟加载的模块很少。但是如果我在网络浏览器中输入延迟加载的模块URL,则用户服务中的数据将显示未定义。我该如何解决?
用户服务
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { HttpClient } from '@angular/common/http';
@Injectable({ providedIn: 'root' })
export class UserService {
private isUserLoggedIn;
private sideNavstatus;
private subsideNavstatus;
public username;
public userDetails;
public jobCard;
public sideNav;
public subsideNav;
public sidestat;
public subsidestat;
constructor() {
this.isUserLoggedIn = false;
}
setUserLoggedInStatus(status) {
this.isUserLoggedIn = status;
this.username = 'User_1';
this.userDetails = {
name: {
fristName: "Carolyn",
middleName: "Ann",
lastName: "Stewart",
},
profileImages: 'assets/images/dummy_back_end/user_1.png',
};
this.sideNav = true;
this.subsideNav = true;
this.sideNavstatus = this.sideNav;
this.subsideNavstatus = this.subsideNav;
this.jobCard = {
jobCardTitle: {
title: "Lorem Ipsum is simply dummy text",
from: "Theresa Jenkins",
}
}
}
getUserLoggedIn() {
return this.isUserLoggedIn;
}
}
应用模块
@NgModule({
declarations: [
AppComponent,
DashboardComponent,
UserComponent,
NotfoundComponent,
LoginComponent,
],
imports: [
BrowserModule,
SharableModule,
// UserModule
// Chart
],
// providers:[UserService,AuthguardGuard],
bootstrap: [AppComponent],
})
export class AppModule { }
platformBrowserDynamic().bootstrapModule(AppModule);
应用程序路由
import { NgModule } from '@angular/core';
export const routes: Routes = [
{ path: ' ', redirectTo: '/login', pathMatch: 'full' },
{ path: 'login', component: LoginComponent },
{
path: 'customers',
loadChildren: './customer/customer.module#CustomerModule'
},
{
path: 'dashboard', canActivate: [AuthguardGuard], component:
DashboardComponent
},
{
path: 'requests', loadChildren: './job-card/job-
card.module#JobCardModule'},
{ path: '**', component: NotfoundComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
客户模块
@NgModule({
imports: [
CommonModule,
CustomerRoutingModule,
SharableModule,
FormsModule,
QuillModule,
// UserModule
],
declarations: [
CustomerlistComponent
],
export class CustomerModule { }