開發時常用的參考資料
可參考 CLI 命令參考手冊,下列為 generate component 的 command
$ ng g component home/component/my-new-component
# => 组件 | 相對生成組件生成位置在項目的根目錄的
# src/app/home/component(指令其他等等都可以用該方式生成)
# ng g component my-component | home/component/my-new-component
$ ng g directive my-new-directive => 指令
$ ng g pipe my-new-pipe => 管道
$ ng g guard my-new-guard => 守護層
$ ng g service my-new-service => 服務
$ ng g class my-new-class => 類
$ ng g interface my-new-interface => 接口
$ ng g enum my-new-enum => 枚舉
$ ng g module my-module => 模塊
$ ng new angular-tour-of-heroes
Angular 有 lazy page 的功能,可以把相同 modules 的分為一類,因此就以此來作為專案的分類
├── logs // Server Side Render 預設 log 路徑
├── server // 做伺服器渲染使用的 module
├── src // 專案主要程式
├── app
├── assets
├── fonts
├── i18n // 多語系檔案
└── image
├── config
├── modules // 所有 modules, 包含 core module, lazyload module, share module
├── ...
├── core // 主要模組
├── components // 非頁面類型的 component
├── directive
├── guard
├── models // factory, base class (放一些不知道放哪的類別,需要再討論)
├── pages // 頁面類型的 component
├── pipes
└── services
├── styles
└── font-icon
├── environments
└── ...
└── ...
NgModule的metadata有下面幾項:
Components/Directives/Pipes
的列表,聲明這個Module的內部成員每一個專案都一定會有一個根模組,也就是root module,我們會在main.ts去做Bootstrap這個根模組的動作,讓整個APP可以運行起來。
// main.js
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule);//用這一串文字來運行根模組AppModule
在bootstrap的動作裡,會建立好執行環境並把在src/app/app.module.ts
裡設定的bootstrap陣列裡的元素取出來並透過在該成員裡設定的selector,讓我們可以在src/index.html
來顯示這個元件的VIEW。
How To Extend Classes with Angular Component Inheritance | DigitalOcean
// app/app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule } from '@angular/common/http';
@NgModule({
imports: [
BrowserModule,
// import HttpClientModule after BrowserModule.
HttpClientModule,
],
declarations: [
AppComponent,
],
bootstrap: [ AppComponent ]
})
export class AppModule {}
```
[Angular - 使用 HTTP 與後端服務進行通訊](https://angular.tw/guide/http#setup-for-server-communication)
## Zone.js
[[Angular] NgZone 的應用](https://blog.kevinyang.net/2019/02/14/ng-ngzone/)
## angular 會對 url 中的 () 去作判斷
https://github.com/angular/angular/issues/10280
[question ](https://www.notion.so/question-f4a7e9a4d35341378dffd3bccd6bb065)
[i18n tranlate ](https://www.notion.so/i18n-tranlate-335ecc06bd0349bfa51bba718327a164)
[Angular for SSR](https://www.notion.so/Angular-for-SSR-0cb5908f871c4a96bb2cf6d8d2cc3603)
[Router](https://www.notion.so/Router-03b68bca16aa433eb0616f0fa1b223c4)
[Life Hooks](https://www.notion.so/Life-Hooks-23eb905e772f4901955bb5cf27fb280b)
[Directive](https://www.notion.so/Directive-1693564dfc8d45fdbb1fe9c06310e835)
[Decorators](https://www.notion.so/Decorators-bd2331d06164495db2804f206eb9d2e4)
[Resolver](https://www.notion.so/Resolver-9a345add174d43bea66d9ba93cc244ff)
[Blog](https://www.notion.so/Blog-dae39f67de074502a56d139b5a6d351f)
[Unit Testing (Jest)](https://www.notion.so/Unit-Testing-Jest-dbc4ce76d3e14019bf6aaab16db0aca3)
[Form](https://www.notion.so/Form-f727ebd646ae46b9a0db2b661a68a771)
Yes, you can still use your general member account to shop at TECHDesign:
```jsx
public auth$ = new ReplaySubject<AuthInfo | null>(1);
constructor(private apiSystemService: ApiSystemService) {}
initUserRoles() {
return this.apiSystemService
.getCheckAuth()
.pipe(
tap((ret: any) => {
this.userConfig = ret.data.config;
this.userRoles = ret.data.roles;
this.auth$.next(ret.data);
})
)
.toPromise();
}
```
```jsx
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { AuthService } from '../services/auth.service';
@Injectable({
providedIn: 'root',
})
export class LoginGuard implements CanActivate {
constructor(private router: Router, private authService: AuthService) {}
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
// 因為 initialNavigation: 'enabledBlocking' 這個設定的關係,route navigate不會等到 APP_INITIALIZER 完成才發生,
// 因此必須要透過 訂閱 auth$ 的方式來等到 checkAuth api 返回。
return this.authService.auth$.pipe(
map((data) => {
if (!this.authService.isLogin()) {
const url = `/user/login?then=${state.url}`;
return this.router.parseUrl(url);
}
return true;
})
);
}
}
```
[**ng2-file-upload**](https://www.notion.so/ng2-file-upload-034cf6a5408846ca801cd43b1ecedea8)
[Element](https://www.notion.so/Element-cf0bb4f09ac742faa4398a4f81f7ba5d)
名稱: Angular Files
識別碼: alexiv.vscode-angular2-files
描述: Quickly scaffold angular file templates
版本: 1.6.4
發行者: Alexander Ivanichev
VS Marketplace 連結: https://marketplace.visualstudio.com/items?itemName=alexiv.vscode-angular2-files
可以直接在 files 上面直接建立 component, servicer, guarde, 等等
[Angular 深入淺出三十天] Day 04 - 資料夾結構說明 - iT 邦幫忙::一起幫忙解決難題,拯救 IT 人的一天
響應式表單提供了一種模型驅動的方式來處理表單輸入,其中的值會隨時間而變化。本文會向你展示如何建立和更新基本的表單控制元件,接下來還會在一個表單組中使用多個控制元件,驗證表單的值,以及建立動態表單,也就是在執行期新增或移除控制元件。 form 表單 這裡的 require 建儀是寫在 formGroup 裡面去作理管,才可方便的在 js 中看到何為必填值。 <form [formGroup]="subscribeForm" (ngSubmit)="submit()"> <mat-form-field class="w-full"> <input matInput required type="email" formControlName="email" /> <mat-error> Please enter a valid email address </mat-error> </mat-form-field>
Jul 15, 2024angular 原生的 number 需要特別去看一下 decimaPipe
Jul 15, 2024asdf
Dec 1, 2022開發 Angular 就不能不知道 Angular CLI 這個超級好用的命令列工具,有了這個工具,原本渾沌的開發環境,頓時清晰,許多繁瑣的瑣事,一個命令就搞定!這邊是我自己的操作筆記,讓記憶力不佳的我,有個地方可以方便查詢。 這裡的內容不保證最新,但會盡量持續更新。 最即時的文件請參考 Angular CLI 在 Github 上的文件,例如要查 ng new 這個指令的用法,請參考這個連結。 安裝 建議使用 Node.js 的 npm 套件管理工具來安裝 Angular CLI,請使用以下指令安裝: npm install -g angular-cli
Dec 1, 2022or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up