填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫Home

嚴格模式

Strict mode

建立新工作區或應用程式時,可以選擇使用 --strict 標誌以嚴格模式建立它們。

When you create a new workspace or an application you have an option to create them in a strict mode using the --strict flag.

啟用此標誌將使用一些新設定來初始化新的工作區或應用程式,這些設定可以改善可維護性,幫助你提前發現錯誤。此外,使用這些更嚴格設定的應用程式更容易進行靜態分析,這可以幫助 ng update 命令在更新到 Angular 的將來版本時更安全,更準確地重構程式碼。

Enabling this flag initializes your new workspace or application with a few new settings that improve maintainability, help you catch bugs ahead of time. Additionally, applications that use these stricter settings are easier to statically analyze, which can help the ng update command refactor code more safely and precisely when you are updating to future versions of Angular.

具體來說, strict 標誌執行以下操作:

Specifically, the strict flag does the following:

你可以在工作區一級和專案一級應用這些設定。

You can apply these settings at the workspace and project level.

要使用嚴格模式建立新的工作空間和應用程式,請執行以下命令:

To create a new workspace and application using the strict mode, run the following command:

ng new [project-name] --strict
      
      ng new [project-name] --strict
    

要在現有的非嚴格工作空間內以嚴格模式建立新應用程式,請執行以下命令:

To create a new application in the strict mode within an existing non-strict workspace, run the following command:

ng generate application [project-name] --strict
      
      ng generate application [project-name] --strict