Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 4: changing url, but component is not rendered

I'm trying to link a component from one component using routerLink = "selected"

 const routes: Routes = [
      {
        path: '',
        children: [
          {
            path: 'account',
            component: AccountComponent,
            children: [
              {
                path: 'selected',
                component: SelectedComponent,
              },
            ],
          },

        ]
      }
    ];

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

This is AccountComponent

    import { Component, OnInit, AfterViewInit } from '@angular/core';
    import { Router, ActivatedRoute, RouterModule } from '@angular/router';
    import { HttpClient, HttpHeaders } from '@angular/common/http';
    import { Http, Response, Headers } from '@angular/http';
    @Component({
      selector: 'app-list-accounts',
      templateUrl: './accounts-list.component.html',
      styleUrls: ['./accounts-list.component.scss']
    })
    export class AccountComponent implements OnInit {

      constructor(private http: HttpClient, private router: Router) { }
     ngOnInit() {}
}

The url is changing to the desired like this dashboard/account/selected, but the view is not loading.

like image 960
yer Avatar asked Apr 09 '18 19:04

yer


1 Answers

Add <router-outlet></router-outlet> to AccountComponent. Read more in the docs.

like image 190
Tomasz Kula Avatar answered Oct 06 '22 10:10

Tomasz Kula