• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
彪ge
博客园    首页    新随笔    联系   管理    订阅  订阅
Angular7.1.4+Typescript3.1框架学习(二)
Angular7常用命令介绍

接着第一部分,这篇文章就 Angular cli进行介绍总结:

1. ng g:列出当前命令

ng g

  需在angular工程文件夹下执行:

C:\Users\zb\angulardemo\heroes>ng g
Generates and/or modifies files based on a schematic.
usage: ng generate <schematic> [options]

arguments:
  schematic
    The schematic or collection:schematic to generate.

options:
  --defaults
    When true, disables interactive input prompts for options with a default.
  --dry-run (-d)
    When true, runs through and reports activity without writing out results.
  --force (-f)
    When true, forces overwriting of existing files.
  --help
    Shows a help message for this command in the console.
  --interactive
    When false, disables interactive input prompts.

Available Schematics:
  Collection "@schematics/angular" (default):
    appShell
    application
    class
    component
    directive
    enum
    guard
    interface
    library
    module
    pipe
    service
    serviceWorker
    universal

2.  ng generate component component-name:该命令会把生成的组件,

     添加到 src/app/app.module.ts 文件中 @NgModule 的 declarations 列表中声明:

3. ng generate service: 创建服务文件

ng generate service hero

该命令会在 src/app/hero.service.ts 中生成 HeroService 类的骨架。 HeroService类的代码如下:

import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root',
})
export class HeroService {

  constructor() { }

} 

4. ng generate module app-routing --flat --module=app:添加 AppRoutingModule

ng generate module app-routing --flat --module=app
  • --flat 把这个文件放进了 src/app 中,而不是单独的目录中。
  • --module=app 告诉 CLI 把它注册到 AppModule的 imports 数组中。
生成的代码如下:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

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

 

 

 

posted on 2019-03-22 15:45  彪ge  阅读(233)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3