首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么RoutingModule不能在我的角度应用程序中工作?

为什么RoutingModule不能在我的角度应用程序中工作?
EN

Stack Overflow用户
提问于 2018-10-07 17:40:27
回答 2查看 289关注 0票数 0

编辑:请注意,在尝试将我的应用程序模块划分为功能模块以延迟加载之前,一切都很好。

因此,我试图将我的应用程序模块分成其他功能模块,这样我就可以在我的角度应用程序中使用延迟加载,

但我犯了个错误

“未明错误:模板解析错误:无法绑定到'routerLink‘,因为它不是'h4’的已知属性。(“ng:///CastraModule/CastrasComponent.html@18:85”-3“>]routerLink=”/profile/{castra.id}}/public“>{castra.name} "):TemplateParser.push../node_modules/@angular/compiler/fesm5/compiler.js.TemplateParser.parse (compiler.js:215) at syntaxError (compiler.js:14687 )) JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._parseTemplate (compiler.js:22687) at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileTemplate (compiler.js:22674) compiler.js:22617 at Set.forEach () at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler.JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents (compiler.js:22526) _compileComponents (compiler.js:22617)在compiler.js:22527 at Object.then (compiler.js:206)

这是我的特色模块

代码语言:javascript
复制
(Imports)

@NgModule({
declarations: [
CastrasComponent,
ProfileComponent,
PublicComponent,
MenuComponent,
ReservationComponent
],
imports: [
CommonModule,
TestRoutingModule
]
})
export class CastraModule { }

我的TestRoutingModule

代码语言:javascript
复制
(Imports)
const testRoutes: Routes = [
{path: 'test', component: TestComponent},
{
path: 'profile/:id', component: ProfileComponent,
children: [
  {path: '', redirectTo: '/profile/:id/public', pathMatch: 'full'},
  {path: 'public', component: PublicComponent},
  {path: 'menu', component: MenuComponent},
  {path: 'reservation', component: ReservationComponent},
  ]
 }
]

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

测试模块是在应用程序模块中导入的,那么问题是什么?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-10-07 17:44:44

你可能需要?将它包装在<a> and </a>

代码语言:javascript
复制
<h4><a routerLink="menu">Part1</a></h4>

编辑

您需要将使用路由器指令(如imports: []或routerLink )的每个模块的RouterModule添加到RouterOutlet。

票数 1
EN

Stack Overflow用户

发布于 2018-10-07 19:04:05

您可以尝试使用RouterModule.forRoot(TestRoutes)而不是RouterModule.forChild(TestRoutes),它可以在我的路由器文件中工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52691162

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档