最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

ionic2中使用自動生成器的方法

 更新時(shí)間:2018年03月04日 15:26:26   作者:cjxhd  
這篇文章主要介紹了ionic2中使用自動生成器的方法,需要的朋友可以參考下

ionic generator是命令行的功能,ionic2自動幫我們創(chuàng)建應(yīng)用程序,從而節(jié)省了大量的時(shí)間,并增加我們的速度來開發(fā)一個(gè)項(xiàng)目的關(guān)鍵部分。

ionic generator使我們可以自動創(chuàng)建以下幾部份:

•component
•directive
•page
•provider

一、創(chuàng)建頁面:ionic g page [PageName]

通過這個(gè)命令創(chuàng)建一個(gè)新的頁面,ionic2項(xiàng)目中這個(gè)命令使​​用最多

我們只需要進(jìn)入我們的命令行中,并運(yùn)行下面的命令:

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>

二、創(chuàng)建組件:ionic g component [ComponentName]

組件是一段代碼,可以在我們的應(yīng)用程序的任何部分使用

通過這個(gè)命令創(chuàng)建一個(gè)組件:

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'; 
 } 
}

三、創(chuàng)建指令:ionic g directive [DirectiveName]

指令,我們的應(yīng)用程序可以在任何元素上使用的修飾符屬性.

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'); 
 } 
}

四、創(chuàng)建服務(wù)提供者:ionic g provider [ProviderName]

現(xiàn)在創(chuàng)建一個(gè)新的服務(wù)(提供者),提供者負(fù)責(zé)處理數(shù)據(jù)的REST API的連接,本地存儲,SQLite的等等。

要?jiǎng)?chuàng)建它,我們?nèi)ミ\(yùn)行以下命令我們的終端:

ionic g provider userService 
# Results: 
√ Create app/providers/user-service/user-service.ts

服務(wù)代碼如下:

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); 
  }); 
 }); 
 } 
}

五、創(chuàng)建管道pipe:ionic g pipe [PipeName]

該管道的變化,我們可以對任何數(shù)據(jù)使用我們的模板,如以大寫字母顯示文本,顯示貨幣值,日期格式等。

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(); 
 } 
}

最后,我們生成的應(yīng)用程序結(jié)構(gòu)如下圖:

我們的項(xiàng)目將存放在一個(gè)更加有序和更多的控制方式,這一切都可以手動實(shí)現(xiàn),但用ionic generator來做,可以節(jié)省寶貴的時(shí)間來創(chuàng)造這些內(nèi)容。

總結(jié)

以上所述是小編給大家介紹的ionic2中使用自動生成器的方法,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時(shí)回復(fù)大家的!

相關(guān)文章

最新評論

濮阳县| 商河县| 伊通| 万全县| 丹凤县| 左云县| 阿克| 新兴县| 西华县| 宝清县| 新野县| 武夷山市| 高唐县| 黄陵县| 津市市| 寻甸| 满城县| 色达县| 五寨县| 桑日县| 井研县| 独山县| 九寨沟县| 丹东市| 伽师县| 梁平县| 无极县| 黔西县| 获嘉县| 孙吴县| 道孚县| 包头市| 海伦市| 留坝县| 定安县| 松阳县| 黔西| 常熟市| 赣州市| 江达县| 丰原市|