使用 Yeoman 向 mean 中添加一个 CRUD 模块的设计

##生成talks模块
在应用程序的根目录,输入

yo meanjs:crud-module talks

响应提示:

  • 选择所有四个补充文件夹(css、img、directives 和 filters)。
  • 回答 Yes,将 CRUD 模块链接添加到菜单。
  • 当生成器询问要使用哪个菜单时,接受默认设置(topbar)。

如下所示

$ yo meanjs:crud-module talks
[?] Which supplemental folders would you like to include in your angular module? 
css, img, directives, filters
[?] Would you like to add the CRUD module links to a menu? Yes
[?] What is your menu identifier? topbar
   create app/controllers/talks.server.controller.js
   create app/models/talk.server.model.js
   create app/routes/talks.server.routes.js
   create app/tests/talk.server.model.test.js
   create public/modules/talks/config/talks.client.routes.js
   create public/modules/talks/controllers/talks.client.controller.js
   create public/modules/talks/services/talks.client.service.js
   create public/modules/talks/tests/talks.client.controller.test.js
   create public/modules/talks/config/talks.client.config.js
   create public/modules/talks/views/create-talk.client.view.html
   create public/modules/talks/views/edit-talk.client.view.html
   create public/modules/talks/views/list-talks.client.view.html
   create public/modules/talks/views/view-talk.client.view.html
   create public/modules/talks/talks.client.module.js

请注意,生成器创建了服务器端基础架构(保存在app目录中):路由、一个控制器、一个模型和一个单元测试。它还在 public/modules/talks 目录下构建了所有客户端工件。
稍后将向Talk对象添加一些自定义字段。在此之前,在浏览器中访问网站,查看默认情况下会得到哪些内容。
单击右上角的Signin链接,输入本系列早些时候创建的用户名和密码,或者单击Signup并创建一组新的凭证。
完成登录后,可以在左上角看到一个 Talks 菜单。从菜单中选择 New Talk 打开一个 HTML 表单,其中提供了一个独立的 Name 字段,

##添加字段
要向 Talk 添加新字段,必须编辑 6 个文件 — 四个用于显示,两个用于持久性:

app/models/talk.server.model.js
public/modules/controllers/talks.client.controller.js
public/modules/talks/views/create-talk.client.view.html
public/modules/talks/views/edit-talk.client.view.html
public/modules/talks/views/view-talk.client.view.html
public/modules/talks/views/list-talks.client.view.html

详细的大家可以自己去实现,实现方法也不难

##常用的Yeoman命令

###生成一个meanjs工程
yo meanjs

###生成一个CRUD模块

yo meanjs:crud-module <module-name>

###创建一个angularJS的模块
yo meanjs:angular-module

###创建一个angular-route
yo meanjs:angular-route

###同理有如下命令
yo meanjs:angular-controller
yo meanjs:angular-view
yo meanjs:angular-service
yo meanjs:angular-directive
yo meanjs:angular-filter
yo meanjs:angular-config
yo meanjs:angular-test
yo meanjs:express-model

##创建express相关命令
yo meanjs:express-controller
yo meanjs:express-route
yo meanjs:express-test