Col*_*rök 0 typescript ionic-framework angular ionic4
当我编译我的 ionic 4 应用程序时,我收到此错误:ERROR in Could not resolve module ./services/services.module relative to app/app-routing.module.ts并且模拟未启动。但是,如果我更改代码中的某些内容并再次编译,代码将成功编译。我查了一下,它可能与路径(绝对/相对)有关。但在这些问题中,解决方案是使用相对路径https://github.com/angular/angular-cli/issues/8641或在这个问题Angular 4 - 无法解析子模块进行路由。由于我已经在使用相对路径,我不知道该怎么做。我在这个应用程序中的文件夹结构是 => src/app/pages 或 services。编辑:当我删除带有所有连接的整个服务文件夹时,问题仍然存在。
路由器模块.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 {}
Run Code Online (Sandbox Code Playgroud)
app-routing.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 {}
Run Code Online (Sandbox Code Playgroud)
根据您提供的信息,我可以看到错误消息所指的模块 (ServiceModule) 看起来不正确:
{ path: 'services', loadChildren: './services/services.module#ServicesPageModule' },
Run Code Online (Sandbox Code Playgroud)
这意味着它是两件事之一:
/services/services.module.ts存在export class ServicesPageModule {}内部/services/services.module.ts文件根据您的评论,您似乎不知道项目中的服务页面是什么。
Angular Service 是一个类,您可以将其注入到组件中,以便您可以在应用程序的各个部分之间重用和共享逻辑/数据,并强制执行明确的关注点分离。
这不是我们在这里谈论的内容。
根据您的路由文件,在某些时候,您生成了一个名为 services 的页面。或者你自己刚刚把那条线放在那里?
如果您没有服务页面,那么此行不应该在那里,因此只需将其删除。
如果你有一个服务页面,那么它需要匹配路径和模块名称,就像我上面解释的那样。
| 归档时间: |
|
| 查看次数: |
2908 次 |
| 最近记录: |