開始學習Angular啦
首先分析一下Angualr專案里的一些核心檔案,了解他們是做什么的
1.根模塊 app.module.ts
這個檔案是 Angular 的根模塊,告訴 Angular 如何組裝應用
// BrowserModule 瀏覽器決議的模塊
import { BrowserModule } from '@angular/platform-browser';
// Angular 核心模塊
import { NgModule } from '@angular/core';
// 根組件
import { AppComponent } from './app.component';
// @NgModule裝飾器,@NgModule 接受 一個元資料物件,告訴 Angular 如何編譯和啟動應用
@NgModule({
// 配置當前應用運行的組件,每新建一個組件都要將新組件匯入并加入到這里
declarations: [
AppComponent
],
// 配置當前模塊運行依賴的其他模塊
imports: [
BrowserModule
],
// 配置專案所需的服務
providers: [],
// 指定應用的主視圖,這里一般是根組件
bootstrap: [AppComponent]
})
// 暴露根模塊,根模塊不需要匯出任何東西,因為其他組件不需要匯入根模塊
export class AppModule { }
2.根組件 app.component.ts
// 引入核心模塊的 Component
import { Component } from '@angular/core';
@Component({
// css 選擇器,選擇器會告訴 Angular:當在模板 HTML 中找到相應的標簽時,就把該組件實體化在那里
selector: 'app-root',
// 當前組件的 html 模版
templateUrl: './app.component.html',
// 當前組件的樣式
styleUrls: ['./app.component.scss']
})
// 暴露組件
export class AppComponent {
title = 'angular-demo'; // 定義屬性
constructor() {} // 建構式
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/234907.html
標籤:其他
上一篇:JSON
下一篇:CSS中浮動塌陷的解決辦法及分析
