关于Angular版本,Angular官方已经统一命名Angular 1.x同一为Angular JS;Angular 2.x及以上统称Angular;css
CLI是Command Line Interface的简写,是一种命令行接口,实现自动化开发流程,好比:ionic cli、vue cli等;它能够建立项目、添加文件以及执行一大堆开发任务,好比测试、打包和发布。html
官方文档:https://angular.iovue
官方文档:https://angular.io/guide/quickstartnode
GitHub:https://github.com/angular/angular-cligit
Angular Material:https://material.angular.io/github
// 显示当前node和npm版本 $ node -v $ npm -v // node 版本高于6.9.3 npm版本高于3.0.0
$ npm install -g typescript
// 新建项目的时候会自动安装typescript(非全局)因此这里也能够不用安装。
$ npm install -g @angular/cli
通过不算漫长的等待,你的Angular CLI就装好了。确认一下:typescript
$ ng v // 出现下面画面说明安装成功,若是不成功你可能须要uninstall一下,再从新来过 $ ng v _ _ ____ _ ___ / \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _| / △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | | / ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | | /_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___| |___/ @angular/cli: 1.1.1 node: 7.10.0 os: darwin x64
$ ng new my-app
这里要等好久啊,大概要下载141M东西。
若是你已经建好了项目文件夹就可使用ng init my-app来新建项目,ng init和ng new的区别是ng new会帮咱们建立一个和项目名称相同的文件夹。npm
趁着它在下载,来看一下运行ng new以后Angular cli已经帮咱们干了什么:json
$ ng new helloKeriy installing ng create .editorconfig create README.md create src/app/app.component.css // 使用HTML模板、CSS样式和单元测试定义AppComponent组件。 它是根组件,随着应用的成长它会成为一棵组件树的根节点。 create src/app/app.component.html create src/app/app.component.spec.ts create src/app/app.component.ts // 定义AppModule,这个根模块会告诉Angular如何组装该应用 create src/app/app.module.ts create src/assets/.gitkeep // 这个文件夹下你能够放图片等任何东西,在构建应用时,它们全都会拷贝到发布包中。 create src/environments/environment.prod.ts create src/environments/environment.ts create src/favicon.ico // 每一个网站都但愿本身在书签栏中能好看一点。 请把它换成你本身的图标。 create src/index.html // 宿主页面 create src/main.ts create src/polyfills.ts create src/styles.css // 公共样式 create src/test.ts // 这是单元测试的主要入口点 create src/tsconfig.app.json create src/tsconfig.spec.json create src/typings.d.ts create .angular-cli.json // Anguar 编译依赖 create e2e/app.e2e-spec.ts // e2e 端对端测试目录 create e2e/app.po.ts create e2e/tsconfig.e2e.json create .gitignore create karma.conf.js create package.json // Angular 的依赖包 create protractor.conf.js create tsconfig.json // TypeScript 编译器的参数 create tslint.json Successfully initialized git. Installing packages for tooling via npm. Installed packages for tooling via npm. Project 'helloKeriy' successfully created.
这里强烈推荐使用淘宝镜像安装:bootstrap
$ ng new helloKeriy --skip-install // 先跳过npm安装 $ cd helloKeriy $ cnpm install // 使用淘宝源安装
安装完成以后就能够启动项目了:
cd helloKeriy
ng serve -open
ng serve命令会启动开发服务器,监听文件变化,并在修改这些文件时从新构建此应用。
使用--open(或-o)参数能够自动打开浏览器并访问http://localhost:4200/。
接下来你将看到:
官方安装说明:https://material.angular.io/guide/getting-started
npm install --save @angular/material @angular/cdk @angular/animations
而后执行修复
npm audit fix
将BrowserAnimationsModule导入应用程序以启用动画支持。
import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; @NgModule({ ... imports: [BrowserAnimationsModule], ... }) export class PizzaPartyAppModule { }
示例:打开app.module.ts并修改:
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { AppComponent } from './app.component'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, BrowserAnimationsModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
import {MatButtonModule, MatCheckboxModule} from '@angular/material'; @NgModule({ ... imports: [MatButtonModule, MatCheckboxModule], ... }) export class PizzaPartyAppModule { }
示例:打开app.module.ts并修改:
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import {MatButtonModule, MatCheckboxModule} from '@angular/material'; import { AppComponent } from './app.component'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, BrowserAnimationsModule, MatButtonModule, MatCheckboxModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
包含主题是将全部核心和主题样式应用于您的应用程序所必需的。要开始使用预先构建的主题,请在应用程序中全局包含Angular Material的预构建主题之一。若是您正在使用Angular CLI,则能够将其添加到styles.css中。
若是您不使用Angular CLI,则能够经过 index.html 中的<link>元素包含预构建的主题。有关主题的更多信息以及有关如何建立自定义主题的说明,请参阅主题指南。
@import "~@angular/material/prebuilt-themes/indigo-pink.css";
npm install --save hammerjs
而后在 src/main.ts 中引入
import 'hammerjs';
若是您想将mat-icon组件与正式的材质设计图标一块儿使用,请在 index.html 中加载图标字体。
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">