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 ...
随机推荐
- Linux kernel Programming - Concurrency and Race Conditions
Concurrency and Its Management Race condition can often lead to system crashes, memory leak,corrupte ...
- Html5 标签三(图片)
1.图片标签 2.属性 一 图片标签 1.<img src="" alt=""> src可以是绝对路径.相对路径. 绝对路径:外部.内部(D:/Ht ...
- React-使用styled-components
1.安装 npm install --save styled-components 2.简单使用 style.js: import styled from 'styled-components'; i ...
- 转:判断js中的数据类型的几种方法
判断js中的数据类型有一下几种方法:typeof.instanceof. constructor. prototype. $.type()/jquery.type(),接下来主要比较一下这几种方法的异 ...
- Linux 开启端口命令
编者按 今天在配置Zookeeper集群的时候,碰到下面的问题: 这里说明是主机192.168.116.129:3888没有连通. 首先ping了一把,是通的,说明主机之间是连通的,然后再检查开放的端 ...
- Solr数据库导入
Solr数据库导入 1.在MySQL中创建一张表t_solr,并插入测试数据. 2.把E:\Solr\solr-4.10.4\example\example-DIH\solr\db\conf下的adm ...
- ABP+AdminLTE+Bootstrap Table权限管理系统第十一节--Bootstrap Table用户管理列表以及Module Zero之用户管理
返回总目录:ABP+AdminLTE+Bootstrap Table权限管理系统一期 用户实体 用户实体代表应用的一个用户,它派生自AbpUser类,如下所示: public class User : ...
- kill方法
删除磁盘上的文件. 语法 Kill 路径名 所需的_路径名_参数是一个字符串表达式,指定要删除的一个或多个文件名. _Pathname_可能包括驱动器和目录或文件夹. 例子删除当前路径下的TXT文档 ...
- 普通程序员看k8s基于角色的访问控制(RBAC)
一.知识准备 ● 上一节描述了k8s的账户管理,本文描述基于角色的访问控制 ● 网上RBAC的文章非常多,具体概念大神们也解释得很详细,本文没有站在高屋建瓴的角度去描述RBAC,而是站在一个普通程序员 ...
- cf166e 在四面体上寻找路线数 递推,取模
来源:codeforces E. Tetrahedron You are given a tetrahedron. Let's mark its vertices ...