angular cli 学习

ng generate

ytj@ytj MINGW64 /e/angular2/awesome-tutorials/angular2/ng2-study (chap01)
$ ng g cl eqx-c
installing class
  create src\app\eqx-c.ts

ytj@ytj MINGW64 /e/angular2/awesome-tutorials/angular2/ng2-study (chap01)
$ ng g c eqx-component
installing component
  create src\app\eqx-component\eqx-component.component.css
  create src\app\eqx-component\eqx-component.component.html
  create src\app\eqx-component\eqx-component.component.spec.ts
  create src\app\eqx-component\eqx-component.component.ts
  update src\app\app.module.ts

ytj@ytj MINGW64 /e/angular2/awesome-tutorials/angular2/ng2-study (chap01)
$ ng g d eqx-directive
installing directive
  create src\app\eqx-directive.directive.spec.ts
  create src\app\eqx-directive.directive.ts
  update src\app\app.module.ts

ytj@ytj MINGW64 /e/angular2/awesome-tutorials/angular2/ng2-study (chap01)
$ ng g e eqx-e
installing enum
  create src\app\eqx-e.enum.ts

ytj@ytj MINGW64 /e/angular2/awesome-tutorials/angular2/ng2-study (chap01)
$ ng g g eqx-guard
installing guard
  create src\app\eqx-guard.guard.spec.ts
  create src\app\eqx-guard.guard.ts
  WARNING Guard is generated but not provided, it must be provided to be used

ytj@ytj MINGW64 /e/angular2/awesome-tutorials/angular2/ng2-study (chap01)
$ ng g i eqx-interface
installing interface
  create src\app\eqx-interface.ts

ytj@ytj MINGW64 /e/angular2/awesome-tutorials/angular2/ng2-study (chap01)
$ ng g m eqx-module
installing module
  create src\app\eqx-module\eqx-module.module.ts

ytj@ytj MINGW64 /e/angular2/awesome-tutorials/angular2/ng2-study (chap01)
$ ng g p eqx-pipe
installing pipe
  create src\app\eqx-pipe.pipe.spec.ts
  create src\app\eqx-pipe.pipe.ts
  update src\app\app.module.ts

ytj@ytj MINGW64 /e/angular2/awesome-tutorials/angular2/ng2-study (chap01)
$ ng g s eqx-service
installing service
  create src\app\eqx-service.service.spec.ts
  create src\app\eqx-service.service.ts
  WARNING Service is generated but not provided, it must be provided to be used

总结:
1、class,enum,interface 生成简单的代码:

export class EqxC {
}
export enum EqxE {
}
export interface EqxInterface {
}

2、component,directive,pipe 会自动更新app.module文件:
2.1)import 组件
2.2)在declarations 追加组件声明
3、guard,service 使用前需要provided, 最好在app.module.ts 中使用

providers: [
  {provide: 'auth',  useClass: AuthService}
]

方式,整个模块内都可以通过@Inject使用.
4、module,component 会生成文件夹。

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

@NgModule({
  imports: [
    CommonModule
  ],
  declarations: []
})
export class EqxModuleModule { }

注意这里引用的是 CommonModule,而不像app.module.ts中引用的是BrowserModule
5、几个参数说明:

--prefix (String) (Default: null) Specifies whether to use the prefix. //selector 前缀
--flat (Boolean) Flag to indicate if a dir is created. //是否生成目录
--export (Boolean) (Default: false) Specifies if declaring module exports the component. // 是否在模块中导出

6、generate.js 源码说明:

angular cli 学习_第1张图片
generate.png

你可能感兴趣的:(angular cli 学习)