- Hands-On Full Stack Web Development with Angular 6 and Laravel 5
- Fernando Monteiro
- 284字
- 2021-07-23 19:18:54
Adding a new module
In this example, we will, so that you can see how to build applications using the Angular CLI. Even in this very basic example, we will cover the following points:
- How to organize an Angular application
- Creating modules
- Creating services
- Template data binding
- Running an application in production
Now, let's create a module that shows us a list of beers:
- Open VS Code, and, inside the integrated Terminal, type the following command:
ng g module beers
Note that the command ng g module is a shortcut to ng generate module <module-name>, and this command just creates the module; we need to add routes, components, and templates, and also import the beers module in app.modules.ts, at the root of the app folder. The preceding command will generate the following structure and file content inside of our project: src/app/beers/beers.module.ts. The beers.module.ts contents are as follows:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
@NgModule({
imports: [
CommonModule
],
declarations: []
})
export class BeersModule { }
This is a pretty simple boilerplate code, but it is very useful. Now, we will add the missing pieces.
- Add the beers module to your app module; open app.module.ts and replace the code with the following lines:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { BeersModule } from './beers/beers.module';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule,
BeersModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Note that we imported BeersModule and added it to the imports array.
- 黑客攻防實戰技術完全手冊:掃描、嗅探、入侵與防御
- 計算機網絡安全實訓教程(第二版)
- Go Web Scraping Quick Start Guide
- 智慧城市中的移動互聯網技術
- Building RESTful Web Services with Spring 5(Second Edition)
- 通信簡史:從信鴿到6G+
- 城域網與廣域網(第2版)
- Microsoft Dynamics CRM 2011 Applications(MB2-868) Certification Guide
- 4G小基站系統原理、組網及應用
- 端到端QoS網絡設計
- 5G時代的大數據技術架構和關鍵技術詳解
- 智慧城市中的物聯網技術
- 黑客與反黑工具使用詳解
- OSPF協議原理與功能拓展
- 路由與交換技術