欢迎来到 Angular 的世界!以下是一些关于如何开始使用 Angular 的基本步骤。
环境准备
在开始之前,请确保您已经安装了以下工具:
创建新项目
使用 Angular CLI 创建一个新的 Angular 项目:
ng new my-angular-project
这将在当前目录下创建一个新的 Angular 项目,名为 my-angular-project
。
项目结构
以下是一个简单的 Angular 项目结构:
my-angular-project/
├── node_modules/
├── src/
│ ├── app/
│ │ ├── components/
│ │ │ └── my-first-component/
│ │ │ ├── my-first-component.html
│ │ │ ├── my-first-component.ts
│ │ │ └── my-first-component.css
│ ├── assets/
│ ├── environments/
│ ├── index.html
│ ├── main.ts
│ ├── styles.css
│ └── polyfills.ts
├── .angular-cli.json
├── package.json
└── README.md
编写第一个组件
在 src/app/components
目录下创建一个新的组件 my-first-component
。
ng generate component my-first-component
这将在 src/app/components
目录下创建一个名为 my-first-component
的组件。
运行项目
在项目根目录下运行以下命令以启动开发服务器:
ng serve
默认情况下,Angular 开发服务器将在 http://localhost:4200/
上运行。
了解更多
要了解更多关于 Angular 的信息,请访问我们的 Angular 文档。
Angular Logo