Saturday, September 23, 2017

How to create angular 4 module

This tutorial assuming all prerequisite to start an Angular 4 application has been properly setup with Angular cli.

To create angular 4 module, follow the steps below.
1. navigate to the root directory of your Angular 4 application.

2. run the following command to generate a new module class
    ng generate module moduleName

    eg. ng generate module ferrari
3. run the following command to generate a new component under the above module
    ng generate component moduleName/componentName

    eg. ng generate component ferrari/ferrari-list
4. create a routing class in the same directory with module class  

    eg. ferrari-routing.module.ts



5. enter the following content in routing class
import { NgModule }            from '@angular/core';
import { RouterModule }        from '@angular/router';
import { FerrariListComponent } from './ferrari-list/ferrari-list.component';

@NgModule({
  imports: [RouterModule.forChild([
  { path: '', redirectTo: 'ferrariList', pathMatch: 'full'},
  { path: 'ferrariList',    component: FerrariListComponent},
  ])],
  exports: [RouterModule]
})

export class FerrariRoutingModule {}

6. import the routing file to module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FerrariListComponent } from './ferrari-list/ferrari-list.component';
import { FerrariRoutingModule } from './ferrari-routing.module';

@NgModule({
  imports: [
    CommonModule,
    FerrariRoutingModule
  ],
  declarations: [FerrariListComponent ]
})

export class FerrariModule { }

7. lazy load the module in app-routing.module.ts

    "{ path: 'ferrari', loadChildren: 'app/ferrari/ferrari.module#FerrariModule' },"


8. the newly created module is ready to use by calling the path in routerLink

    eg. <a routerLink="ferrari">Ferrari</a>



Done!!


1 comment:

  1. This takes a wide variety|all kinds} of forms, from multi-accounting to abuse bonuses, affiliate fraud, money laundering – and even grey areas corresponding to arbitrage. There is purpose to recommend new reforms, such a banning credit bets and establishing a self-exclusion register, will have some impact in serving to to tackle downside gambling on-line. Casino-style on-line gambling, corresponding to digital slot machines, although absolutely legal in solely six states, has additionally become more and more 더킹카지노 important. That section generated $2.4 billion in income within the first half of 2022, up greater than 43% from a report set in 2021, the AGA mentioned. In the primary half of 2022, U.S. on-line sports bookmakers generated an estimated $2.eight billion in income handling about $42.5 billion in bets, in accordance with the American Gaming Association, a trade group. As of August, Washington and 20 states have allowed on-line wagers on sports, and six states have legalized the apply however have yet to launch legal wagering, the association mentioned.

    ReplyDelete

LinkWithin

Related Posts Plugin for WordPress, Blogger...