Angular2 笔记

安装相关:

安装Angular CLI工具:

npm install -g @angular/cli

创建新应用:

ng new new-app

启动应用服务器

//cd add directory
ng serve --open  //open参数自动打开浏览器

创建新的内容

创建新组件

ng generate component newcomponent

创建服务

ng generate service newservice --module=app //后面的参数把服务自动提供给AppModule

创建模块

ng generate module app-routing --flat --module=app
//--flat 把这个文件放进了 src/app 中,而不是单独的目录中。
//--module=app 告诉 CLI 把它注册到 AppModule 的 imports 数组中

创建类(也可以直接创建一个ts文件)

ng generate class newclass

创建指令

ng generate directive highlight

数据绑定

在html中显示组件中的属性

{{title}}

CSS 类绑定

changed

for循环

{{hero.name}}

属性绑定:



事件绑定:



click me

你可能感兴趣的:(Angular2 笔记)