- 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.
- C++黑客編程揭秘與防范
- 網(wǎng)絡(luò)創(chuàng)新指數(shù)研究
- 智慧城市中的移動(dòng)互聯(lián)網(wǎng)技術(shù)
- 網(wǎng)絡(luò)的琴弦:玩轉(zhuǎn)IP看監(jiān)控
- 中小型局域網(wǎng)組建、管理與維護(hù)實(shí)戰(zhàn)
- 計(jì)算機(jī)網(wǎng)絡(luò)與通信(第2版)
- 計(jì)算機(jī)網(wǎng)絡(luò)原理與應(yīng)用技術(shù)
- 網(wǎng)管員必讀:網(wǎng)絡(luò)管理(第2版)
- 光纖通信系統(tǒng)與網(wǎng)絡(luò)(修訂版)
- 高級(jí)網(wǎng)絡(luò)技術(shù)
- 大型企業(yè)微服務(wù)架構(gòu)實(shí)踐與運(yùn)營(yíng)
- 深入理解計(jì)算機(jī)網(wǎng)絡(luò)
- 圖解物聯(lián)網(wǎng)
- 智慧城市中的物聯(lián)網(wǎng)技術(shù)
- SEO攻略:搜索引擎優(yōu)化策略與實(shí)戰(zhàn)案例詳解