sách gpt4 ai đã đi

angular - “无法解析模块...相对于...”编译应用程序时出错

In lại 作者:行者123 更新时间:2023-12-05 09:13:00 31 4
mua khóa gpt4 Nike

当我编译我的 ionic 4 应用程序时,我得到这个错误:不开始。但是,如果我更改代码中的某些内容并再次编译,代码将成功编译。我查了一下它可能与路径(绝对/相对)有关。但在这些问题中,解决方案是使用相对路径 https://github.com/angular/angular-cli/issues/8641或者在这个问题中Angular 4 - Could not resolve submodule for routing .由于我已经在使用相对路径,所以我不知道该怎么做。我在这个应用程序中的文件夹结构是 => src/app/pages or services。编辑:当我删除包含所有连接的整个服务文件夹时,问题仍然存在。

router.module.ts

 import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

import { TabsPage } from './tabs.page';

const routes: Routes = [
{
path: 'tabs',
component: TabsPage,
children: [
{
path: 'one',
children: [
{
path: '',
loadChildren: '../one/one.module#OnePageModule'
}
]
},
{
path: 'two',
children: [
{
path: '',
loadChildren: '../two/two.module#TwoPageModule'
}
]
},
{
path: 'three',
children: [
{
path: '',
loadChildren: '../three/three.module#ThreePageModule'
}
]
},
{
path: 'four',
children: [
{
path: '',
loadChildren: '../four/four.module#FourPageModule'
}
]
},

{
path: 'five',
children: [
{
path: '',
loadChildren: '../five/five.module#FivePageModule'
}
]
},

{
path: '',
redirectTo: '/tabs/one',
pathMatch: 'full'
}
]
},
{
path: '',
redirectTo: '/tabs/one',
pathMatch: 'full'
}
];

@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class TabsPageRoutingModule {}

应用路由.module.ts

import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';

const routes: Routes = [
{ path: '', loadChildren: './tabs/tabs.module#TabsPageModule' },
{ path: 'one', loadChildren: './one/one.module#OnePageModule' },
{ path: 'filter', loadChildren: './filter/filter.module#FilterPageModule' },
{ path: 'four', loadChildren: './four/four.module#FourPageModule' },
{ path: 'key', loadChildren: './key/key.module#KeyPageModule' },
{ path: 'test', loadChildren: './test/test.module#TestPageModule' },
{ path: 'notifications', loadChildren: './notifications/notifications.module#NotificationsPageModule' },
{ path: 'three', loadChildren: './three/three.module#ThreePageModule' },
{ path: 'five', loadChildren: './five/five.module#FivePageModule' },
{ path: 'two', loadChildren: './two/two.module#TwoPageModule' },
{ path: 'services', loadChildren: './services/services.module#ServicesPageModule' },
{ path: 'settings', loadChildren: './settings/settings.module#SettingsPageModule' },
{ path: 'login', loadChildren: './login/login.module#LoginPageModule' },
{ path: 'signup', loadChildren: './signup/signup.module#SignupPageModule' },
{ path: 'friprofile', loadChildren: './friprofile/friprofile.module#FriprofilePageModule' },
{ path: 'four/:id', loadChildren: './four-details/four-details.module#FourDetailsPageModule' },
{ path: 'two-details', loadChildren: './two-details/two-details.module#TwoDetailsPageModule' },
{ path: 'choose', loadChildren: './choose/choose.module#ChoosePageModule' },
{ path: 'camfilter', loadChildren: './camfilter/camfilter.module#CamfilterPageModule' }
//Changed from four-details -> four/:id
];
@NgModule({
imports: [
RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
],
exports: [RouterModule]
})
export class AppRoutingModule {}

1 Câu trả lời

根据您提供的信息,我可以看出错误消息所指的模块 (ServiceModule) 看起来没有问题:

{ path: 'services', loadChildren: './services/services.module#ServicesPageModule' },

这意味着它是两件事之一:

  1. 该文件不存在 - 查看您的目录并确认 /services/services.module.ts存在
  2. 你在某个时候重命名了文件但没有重命名里面的代码 - 检查是否有 export class ServicesPageModule {}hiện hữu/services/services.module.ts里面文件

(更新)什么是服务?

从您的评论来看,您似乎不知道项目中的服务页面是什么。

Angular 服务是一个可以注入(inject)到组件中的类,这样您就可以在应用的各个部分之间重用和共享逻辑/数据,并强制完全分离关注点。

这不是我们在这里讨论的内容。

根据你的路由文件,在某个时候,你已经生成了一个名为services的页面。还是您自己将那条线放在那里?

如果您没有服务页面,那么这一行不应该在那里,所以只需将其删除即可。

如果您确实有一个服务页面,那么它需要匹配路径和模块名称,就像我上面解释的那样。

关于angular - “无法解析模块...相对于...”编译应用程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57022835/

31 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com