angular.json 是 Angular CLI 的控制塔,它提供了 Angular workspace 和 project 的預設配置。
講解了一些 angular.json 的資料架構。
什麼是 Architect 和 Builders 與他們之間的關係。
Angular CLI 是如何透過 Architect 解析命令的。
如何透過 assets 在打包專案時複製完整的資料。
Angular workspace root level 的一個文件,主要是提供 workspace 的配置與 project 的預設配置,供 Angular CLI 中 build 和 development tool 使用。
A file named angular.json at the root level of an Angular workspace provides workspace-wide and project-specific configuration defaults for build and development tools provided by the Angular CLI. Path values given in the configuration are relative to the root workspace folder.
首先把你的專案改為 ssr
ng add @nguniversal/express-engine
ng 會幫你新建立一些資料,資料結構如下
src/
index.html app web page
main.ts bootstrapper for client app
main.server.ts * bootstrapper for server app
Service providers
增加一個 new service
$ ng g service [NEW_SERVICE_NAME]
可以看到app.module.ts的providers會增加一個名為UserService的類別
providers: [ UserService ]
在使用上,如果已經有設定好providers後,只要在元件的constructor裡面宣告一個變數是providers裡面設定好的service,就可以在元件裡直接取用了