Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 无法从导航栏组件html中调用组件_Angular_Components_Navbar_Angular Router - Fatal编程技术网

Angular 无法从导航栏组件html中调用组件

Angular 无法从导航栏组件html中调用组件,angular,components,navbar,angular-router,Angular,Components,Navbar,Angular Router,我已经创建了一个导航栏,我正在尝试调用其他模块的组件,以便能够从导航栏链接访问不同的页面。 我使用routerlink作为属性来调用组件。以下是更好理解的代码 navbar.component.html <ul class="nav navbar-nav"> <li class="active"><a href="#">Home<span class="sr-only">(current)</span></a></li

我已经创建了一个导航栏,我正在尝试调用其他模块的组件,以便能够从导航栏链接访问不同的页面。 我使用routerlink作为属性来调用组件。以下是更好理解的代码

navbar.component.html

<ul class="nav navbar-nav">
<li class="active"><a href="#">Home<span class="sr-only">(current)</span></a></li>
<li><a routerlink="/fixeddeposits" routerLinkActive="active">Link</a></li>
navbar.component.ts

import { Component,NgModule } from '@angular/core';
import { NavbarModule } from './navbar.module';
 @NgModule({ 
 imports:[NavbarModule],
  })   
 @Component({
  moduleId: module.id,
  selector: 'navbar',
  templateUrl: 'navbar.component.html'
  })

  export class NavbarComponent {
   title = 'app'; 
   }
navbar.module.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { TableComponent } from '../table/table.component';
import { FixedDepositsComponent } from '../fixed-deposits/fixed- 
deposits.component';

const routes: Routes = [

{path: 'table', component: TableComponent},
{path: 'fixeddeposits', component: FixedDepositsComponent},
];

@NgModule({
 imports: [RouterModule.forChild(routes)],
 exports: [RouterModule],
})
export class NavbarRoutingModule { }
export const routedComponents = [
TableComponent,
FixedDepositsComponent,
];
import { NgModule } from '@angular/core';
 import { NavbarRoutingModule, routedComponents } from 
 './navbar.routing.module';

 @NgModule({
   imports: [   
   NavbarRoutingModule,],
   declarations: [
    routedComponents,
   ],
   })
 export class NavbarModule { }
app.routing.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { TableComponent } from './table/table.component';
import { FixedDepositsComponent } from './fixed-deposits/fixed-d 
eposits.component';

const routes: Routes = [

{path: 'table', component: TableComponent},
{path: 'fixeddeposits', component: FixedDepositsComponent},
];
 @NgModule({
  imports: [RouterModule.forRoot(routes)],
   exports: [RouterModule]
  })
 export class AppRoutingModule {}

 export const routingComponents = [TableComponent, FixedDepositsComponent];

当我使用此代码时,我没有收到错误,但当我单击导航栏按钮链接时,我没有重定向到定期存款组件。

路由文件不应该是单独的模块,并且存在一些语法错误,如“routerlink”=>routerlink中的小l

在此处更新了您的代码:


能否将定期存款模块添加到导入:[RouterModule.forChild(routes)],?如果你想使用延迟加载,那么,你可能需要仔细阅读并理解这些示例。你能发布主路由的定义吗?@AdrianF–ciu我在主路由中也尝试过这样做,我已经提到了上面app.routing的代码。ts@WandMaker我是否需要添加fixeddeposit模块,因为我没有为其创建模块,因为我希望通过以下方式将其定义到路由中来访问定期存款组件:{path:'fixeddeposit',component:FixedDepositsComponent},你可以创建你的应用程序的stackblitz版本-然后,有人可以看一看我尝试了上述更改,但没有为我进行训练,当我单击按钮时,没有出现任何错误,但不会重定向到其他组件。下面是我代码的链接:你指出了“routerLink”的错误现在我对路由的概念已经很清楚了。非常感谢你,你的努力真的很有帮助!哦,我试着投票给你的答案,但由于我的声誉低于15,我不能!我一定会尽快做的