Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.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 角度2侧边栏组件不在路线导航上工作_Angular_Angular Components_Angular Router - Fatal编程技术网

Angular 角度2侧边栏组件不在路线导航上工作

Angular 角度2侧边栏组件不在路线导航上工作,angular,angular-components,angular-router,Angular,Angular Components,Angular Router,当我在内部导航时,侧栏组件没有正确响应 当我从login.component.ts运行onSubmit时,它会转到dashboard/home,“home”视图工作正常,我的边栏组件也会加载,但当我单击边栏项目时,routerLink不起作用,下拉列表也不起作用 在我的登录名component.ts上,我进行了一次简单的身份验证,成功后将转到仪表板路径,该路径已 onSubmit(values){ this.http.post('/user/authenticate', loginObj

当我在内部导航时,侧栏组件没有正确响应

当我从login.component.ts运行
onSubmit
时,它会转到dashboard/home,“home”视图工作正常,我的边栏组件也会加载,但当我单击边栏项目时,routerLink不起作用,下拉列表也不起作用

在我的
登录名component.ts
上,我进行了一次简单的身份验证,成功后将转到仪表板路径,该路径已

onSubmit(values){
    this.http.post('/user/authenticate', loginObj)
      .map((res) => res.json())
      .subscribe((res)=> {
        if(res.success == true){
          this.router.navigate(['/dashboard']);
        } else {
          ....
        }
}
在我的dashboard.component.html中

<div id="wrapper" >
  <app-sidebar ></app-sidebar>
      <div id="page-wrapper" class="gray-bg">
         <app-header></app-header>
      <router-outlet></router-outlet>
     </div>
</div>
而这是我的app.modules.ts

//setting up routes

const ROUTES = [
{
  path:'',
  redirectTo:'login',
  pathMatch:'full'
},
 {
   path:'login',
  component:LoginComponent
},{
  path:'dashboard',
    component:DashboardComponent,
  children:[
{
  path:'contacts',
  component:ContactsComponent
},{
  path:'home',
  component:HomeComponent,
}]
}];
对于我的app.component.ts


但它甚至都不起作用,我尝试了许多解决方案并查看了web,找不到正确的答案。问题是我的边栏组件不工作

预期行为


我希望当我在内部导航到我的仪表板路线时,我的组件应该能够正常工作并响应。

不幸的是,您没有发布组件代码。我假设http post来自您的登录组件。我认为问题在于你对
的定位。它应该放在组件的html中,在该组件中有
this.router.navigate(['/dashboard'])。在您的情况下,登录组件。

将此脚本放在侧栏组件中…然后尝试加载

ngOnInit() {
    $(document).ready(() => {
      const trees: any = $('[data-widget="tree"]');
      trees.tree();
    });
  }

请检查上面更新的代码,我的侧栏组件在我单击Nether下拉菜单时不加载routerLink,但通常在站点重新加载时工作正常,不确定我是否理解这里的确切问题。你能用你的代码创建一个plunker吗?虽然它可以回答这个问题,但你应该在答案中添加一个解释。出了什么问题?你的答案应该如何解决这个问题?我的侧边栏的问题是。。。页面需要重新加载才能正常工作侧边栏。。。早些时候,当点击侧边栏部分项目时,它没有打开其子部分…页面需要重新加载
<router-outlet></router-outlet>
ngOnInit() {
    $(document).ready(() => {
      const trees: any = $('[data-widget="tree"]');
      trees.tree();
    });
  }