ionic2中如何使用自动生成器
ionic generator是命令行的功能,ionic2自动帮我们创建应用程序,从而节省了大量的时间,并增加我们的速度来开发一个项目的关键部分。
- component
- directive
- page
- provider
一、创建页面:ionic g page [PageName]
ionic g page login
# Results:
√ Create app/pages/login/login.html
√ Create app/pages/login/login.scss
√ Create app/pages/login/login.ts
login.ts:

import {Component} from '@angular/core';
import {NavController} from 'ionic-angular';
@Component({
templateUrl: 'build/pages/login/login.html',
})
export class LoginPage {
constructor(public nav: NavController) {}
}

login.html:

<ion-header>
<ion-navbar>
<ion-title>
login
</ion-title>
</ion-navbar>
</ion-header> <ion-content padding class="login">
</ion-content>

二、创建组件:ionic g component [ComponentName]
ionic g component myComponent
# Results:
√ Create app/components/my-component/my-component.html
√ Create app/components/my-component/my-component.ts
my-component.ts:

import {Component} from '@angular/core';
@Component({
selector: 'my-component',
templateUrl: 'build/components/my-component/my-component.html'
})
export class MyComponent {
text: string = "";
constructor() {
this.text = 'Hello World';
}
}

ionic g directive myDirective
# Results:
√ Create app/components/my-directive/my-directive.ts
my-directive.ts:

import {Directive} from '@angular/core';
@Directive({
selector: '[my-directive]' // Attribute selector
})
export class MyDirective {
constructor() {
console.log('Hello World');
}
}

四、创建服务提供者:ionic g provider [ProviderName]
ionic g provider userService
# Results:
√ Create app/providers/user-service/user-service.ts
服务代码如下:
user-service.ts:

import {Injectable} from '@angular/core';
import {Http} from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class UserService {
data: any = null;
constructor(public http: Http) { }
load() { if (this.data) {
}
return new Promise(resolve => {
this.http.get('path/to/data.json')
.map(res => res.json())
.subscribe(data => {
this.data = data;
resolve(this.data);
});
});
}
}

五、创建管道pipe:ionic g pipe [PipeName]
ionic g pipe myPipe
# Results:
√ Create app/pipes/myPipe.ts
我们的管道的代码如下
myPipe.ts:

import {Injectable, Pipe} from '@angular/core';
@Pipe({
name: 'my-pipe'
})
@Injectable()
export class MyPipe {
transform(value: string, args: any[]) {
value = value + ''; // make sure it's a string
return value.toLowerCase();
}
}

最后,我们生成的应用程序结构如下图:

ionic2中如何使用自动生成器的更多相关文章
- Ionic2系列——在Ionic2中使用ECharts
在群里看到有人问怎么在Ionic2中集成ECharts来显示图表.当时答应说写个blog,简单写下步骤. 在TypeScript中如果要使用第三方库,必须要有d.ts,也就是定义文件,没有这个文件的话 ...
- Python验证码6位自动生成器
Python验证码6位自动生成器
- Ionic2中集成腾讯Bugly之自定义插件
Ionic2混合开发,入坑系列:Ionic2中集成腾讯Bugly之自定义插件 1.编写Bugly.js代码 var exec = require('cordova/exec'); module.exp ...
- python is、==区别;with;gil;python中tuple和list的区别;Python 中的迭代器、生成器、装饰器
1. is 比较的是两个实例对象是不是完全相同,它们是不是同一个对象,占用的内存地址是否相同 == 比较的是两个对象的内容是否相等 2. with语句时用于对try except finally 的优 ...
- MyBatisPlus性能分析插件,条件构造器,代码自动生成器详解
性能分析插件 我们在平时的开发中,会遇到一些慢sql,测试,druid MP(MyBatisPlus)也提供性能分析插件,如果超过这个时间就停止 不过官方在3.2版本的时候取消了,原因如下 条件构造器 ...
- Mybatis-Plus03 代码自动生成器
先看完Mybatis-Plus01和Mybatis-Plus02再看Mybatis-Plus03 AutoGenerator 是 MyBatis-Plus 的代码生成器,通过 AutoGenerato ...
- Mybatis-plus<一> Springboot框架使用MybatisPlus代码自动生成器
Mybatis-plus<一> Springboot框架使用MybatisPlus代码自动生成器 Mybatis-plus官网: https://mp.baomidou.com/ Demo ...
- 掌握JavaScript中的迭代器和生成器,顺便了解一下async、await的原理
掌握JavaScript中的迭代器和生成器,顺便了解一下async.await的原理 前言 相信很多人对迭代器和生成器都不陌生,当提到async和await的原理时,大部分人可能都知道async.aw ...
- 专门为小白准备的入门级mybatis-plus-generator代码自动生成器,提高开发效率。值得收藏
引入依赖 <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-g ...
随机推荐
- IDEA(jetbrain通用)优雅级使用教程(转)
文章转自 http://www.jianshu.com/p/3160ff832a9b 前面写过一篇IDEA的入门级文章,但是只学会了那些配置啊什么的并不能提高我们的开发效率.事实上,如果你IDEA用 ...
- Linux命令——head/tail
一.head head主要是用来显示档案的开头至标准输出中,默认打印相应文件的开头10 行. 1)命令格式 head [参数] [文件] 2)常用参数 -q 隐藏文件名-v 显示文件名 ...
- node通过http.request向其他服务器上传文件
function upload(callback) { let boundaryKey = '----' + new Date().getTime(); // 用于标识请求数据段 let option ...
- Omi框架学习之旅 - 通过对象实例来实现组件通讯 及原理说明
组件通讯不是讲完了吗(上帝模式还没讲哈),怎么又多了种方式啊. 你484傻,多一种选择不好吗? 其实这个不属于组件通讯啦,只是当父组件实例安装和渲染完毕后,可以执行installed这个方法(默认是空 ...
- SkylineGlobe 如何二次开发实现天际线分析功能
天际线效果: 示例代码: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <h ...
- 2-(基础入门篇)Air202下载开发入门(给Air202下载第一个程序)
http://www.cnblogs.com/yangfengwu/p/8887933.html 资料链接 链接:https://pan.baidu.com/s/1-SRfsKGQ7rZVvFmp1O ...
- (转)Ubuntu init启动流程分析
原文 upstart homepage 现行的Linux distros主流的有两种init方式:一种是广为流传的System V initialization,它来源于Unix并且至今仍被各种Lin ...
- C# 16进制转 Brush 颜色对象
原文:C# 16进制转 Brush 颜色对象 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u014117094/article/details/4 ...
- EZ 2018 06 02 NOIP2018 模拟赛(十七)
这次的比赛是真心比较狗,我TM的写了30min的树剖ZZ地直接memset超时了 话说我既然想到差分就应该去写差分的啊! 好了不过这次Rank还挺高的,终于要打进前10了当然是假的了. 好了下面开始讲 ...
- Asp.Net MVC 获取当前 Controller Action Area
获取控制器名称: ViewContext.RouteData.Values["controller"].ToString(); 获取Action名称: ViewContext.Ro ...