工具简述 Description

Ionic now provides a generator function to create pages and services for your app. This makes going from a basic app to a full featured app with navigation much easier.

To create a page you can use the following command:

# ionic g page <PageName>
ionic g page MyAboutPage

√ Create app/pages/my-about-page/my-about-page.html
√ Create app/pages/my-about-page/my-about-page.js
√ Create app/pages/my-about-page/my-about-page.scss

This will give you a html file, sass file, and a js file with your component definition.

To create a service, you can replace page with provider:

ionic g provider MyData

√ Create app/pages/my-data/my-data.js

This will create a standard class with a simple http get request using Angular’s http class.

命名规范 A quick note on naming conventions

Ionic 2 uses kebob-casing for file names (my-about-page.html) and css classes (.my-about-page), and uses PascalCasing for JavaScript classes in ES6/TypeScript (MyAboutPage). Using this convention, developers can pick up any Ionic 2 project and quickly become productive, similar to Rails.

  • 目录名称 /app/pages/my-about-page/
  • 文件名称 my-about-page.html
  • scss样式 .myaboutpage
  • Class名称 MyAboutPage

微信关注:ryanemax (刘雨飏)
授权协议: CC BY-SA 4.0