This project was generated with Angular CLI version 7.2.1.
ng g c components/first
ng g c components/second
const routes: Routes = [
{ path: 'first', component: FirstComponent },
{ path: 'second', component: SecondComponent }
];
<button type="input" [routerLink]="[ '/first' ]"> first </button>
<button type="input" [routerLink]="[ '/second' ]"> second </button>
<main>
<router-outlet></router-outlet>
</main>
ng g m components/first --routing
ng g m components/second --routing
const routes: Routes = [
{ path: 'first', loadChildren: './components/first/first.module#FirstModule' },
{ path: 'second', loadChildren: './components/second/second.module#SecondModule' }
];
import { FirstComponent } from './first.component';
const routes: Routes = [
{ path: '', component: FirstComponent}
];
import { SecondComponent } from './second.component';
const routes: Routes = [
{ path: '', component: SecondComponent }
];
Note: Declare the components in their respective modules and eliminate the declarations of the components in the main module of the application
ng update @angular/cli @angular/core --allow-dirty
Run ng serve
for a dev server. Navigate to http://localhost:4200/
. The app will automatically reload if you change any of the source files.
Run ng generate component component-name
to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module
.
Run ng build
to build the project. The build artifacts will be stored in the dist/
directory. Use the --prod
flag for a production build.
Run ng test
to execute the unit tests via Karma.
Run ng e2e
to execute the end-to-end tests via Protractor.
To get more help on the Angular CLI use ng help
or go check out the Angular CLI README.