准备工作
1.下载安装mode.js
2.打开cmd执行命令npm install -g @angular/cli
安装angular/cli(只需要安装一次)
创建angular项目
1.创建一个文件目录,并且在cmd中进入这个目录,然后执行代码ng new angulardemo01
(angulardemo01为项目名称)
2.安装好之后cd进入angulardemo01目录,然后执行ng serve --open
打开网页
创建一个组件并使用(在控制台中)
1.在控制台执行ng g component components/news
(意思是在app的目录下创建一个components的文件夹,在components的文件夹下再创建一个news的文件夹)
2.在需要使用的地方调用<app-news></app-news>
创建一个组件并使用(手动创建)
1.在指定目录下创建您需要的文件
2.在app.module.ts文件中需要引入import { NewsComponent } from './components/news/news.component'
,并且在@NgModule中配置
declarations: [
AppComponent,
NewsComponent
],
3.在需要使用的地方调用<app-news></app-news>