1. 创建组件

    在项目所在目录下执行:
ionic g component <ComponentName>
  1. 在src/components中会出现:
——components
|——ComponentName
|——ComponentName.html
|——ComponentName.scss
|——ComponentName.ts
|——components.module.ts
  1. 组件模块:
  • ComponentName.html
<div class="progress-outer">
<div class="progress-inner" [style.width]="progress +'%'">
{{showProgress}}%
</div>
</div>
  • ComponentName.scss
progress-bar {
.progress-outer{
width: 96%;
margin:10px 2%;
padding: 3px;
text-align: center;
background-color: #f4f4f4;
border:1px solid #dcdcdc;
color: #fff;
border-radius: 20px;
} .progress-inner{
min-width: 15%;
white-space: nowrap;
overflow: hidden;
padding: 5px;
border-radius: 20px;
background-color: map_get($colors,primary);
}
}
  • ComponentName.ts
import {Component, Input} from '@angular/core';

@Component({
selector: 'progress-bar',
templateUrl: 'progress-bar.html'
})
export class ProgressBarComponent { @Input('progress') progress:Number;
@Input('showProgress') showProgress:Number; constructor() {
console.log('Hello ProgressBarComponent Component'); } }
  1. 组件通讯
  • @Input
  • @Output
  • my.ts:
import {Component, EventEmitter, Input, Output} from '@angular/core';

/**
* Generated class for the MyComponent component.
*
* See https://angular.io/api/core/Component for more info on Angular
* Components.
*/
@Component({
selector: 'my',
templateUrl: 'my.html'
})
export class MyComponent { @Input('data') data: string;
@Output() parentClick=new EventEmitter(); constructor() {
console.log('Hello MyComponent Component'); }
MCClick(){
this.parentClick.emit({
from:this.data
})
} }
  • my.html:
<div (click)="MCClick()" class="red-text">from {{data}}</div>
  1. 引入自定义控件
  • 在src/app/app.module.ts引入ComponentNameComponent
import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';
.......... import {ComponentsModule} from "../components/components.module" @NgModule({
declarations: [
MyApp,
....
//ProgressBarComponent
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
ComponentsModule
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
....
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
  • 在使用自定义组件的页面所在的module中引入
...
import {ComponentsModule} from "../../components/components.module"
...
@NgModule({
declarations: [
...
],
imports: [
...
ComponentsModule
]
})
export class MyModule{
...
...
}
  • 然后就可以在页面中使用了:
<ion-header>

  <ion-navbar>
<ion-title>testProgressBar</ion-title>
</ion-navbar> </ion-header> <ion-content padding>
<progress-bar [progress]="loadProgress1" [showProgress]="loadProgress"></progress-bar>
</ion-content>

参考网址:

http://e2web.cn/2017/02/27/

http://blog.csdn.net/github_36704158/article/details/76355989

ionic 编写自定义控件的更多相关文章

  1. Qt编写自定义控件二动画按钮

    现在的web发展越来越快,很多流行的布局样式,都是从web开始的,写惯了Qt widgets 项目,很多时候想改进一下现有的人机交互,尤其是在现有的按钮上加一些动画的效果,例如鼠标移上去变大,移开还原 ...

  2. [翻译]Writing Custom Common Controls 编写自定义控件

    摘要:介绍如何编写自定义的控件,用在报表的窗体上(如Edit,Button等)   Writing Custom Common Controls 编写自定义控件 FastReport contains ...

  3. 编写Qt Designer自定义控件(二)——编写自定义控件界面

    接上文:编写Qt Designer自定义控件(一)——如何创建并使用Qt自定义控件 既然是控件,就应该有界面,默认生成的控件类只是一个继承了QWidget的类,如下: #ifndef LOGLATED ...

  4. Qt编写自定义控件插件开放动态库dll使用(永久免费)

    这套控件陆陆续续完善了四年多,目前共133个控件,除了十几个控件参考网友开源的代码写的,其余全部原创,在发布之初就有打算将动态库开放出来永久免费使用,在控件比较完善的今天抽了半天时间编译了多个qt版本 ...

  5. Qt编写自定义控件11-设备防区按钮控件

    前言 在很多项目应用中,需要根据数据动态生成对象显示在地图上,比如地图标注,同时还需要可拖动对象到指定位置显示,能有多种状态指示,安防领域一般用来表示防区或者设备,可以直接显示防区号,有多种状态颜色指 ...

  6. Qt编写自定义控件10-云台仪表盘

    前言 做过安防视频监控的同学都清楚,在视频监控系统软件上都可以看到一个云台控制区域,可以对球机进行下下左右等八个方位的运动控制,还可以进行复位,一般都是美工作图好,然后贴图的形式加入到软件中,好处是程 ...

  7. Qt编写自定义控件9-导航按钮控件

    前言 导航按钮控件,主要用于各种漂亮精美的导航条,我们经常在web中看到导航条都非常精美,都是html+css+js实现的,还自带动画过度效果,Qt提供的qss其实也是无敌的,支持基本上所有的CSS2 ...

  8. Qt编写自定义控件8-动画按钮组控件

    前言 动画按钮组控件可以用来当做各种漂亮的导航条用,既可以设置成顶部底部+左侧右侧,还自带精美的滑动效果,还可以设置悬停滑动等各种颜色,原创作者雨田哥(QQ:3246214072),驰骋Qt控件界多年 ...

  9. Qt编写自定义控件7-自定义可拖动多边形

    前言 自定义可拖动多边形控件,原创作者是赵彦博(QQ:408815041 zyb920@hotmail.com),创作之初主要是为了能够在视频区域内用户自定义可拖动的多个区域,即可用来作为警戒区域,也 ...

随机推荐

  1. BZOJ 2467: [中山市选2010]生成树(矩阵树定理+取模高斯消元)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2467 题意: 思路:要用矩阵树定理不难,但是这里的话需要取模,所以是需要计算逆元的,但是用辗转相减会 ...

  2. 在SSM框架中,multfile转file

    import org.apache.commons.fileupload.disk.DiskFileItem; import org.springframework.web.multipart.Mul ...

  3. 怎样借助Python爬虫给宝宝起个好名字--python 学习

    每个人一生中都会遇到一件事情,在事情出现之前不会关心,但是事情一旦来临就发现它极其重要,并且需要在很短的时间内做出重大决定,那就是给自己的新生宝宝起个名字. 因为要在孩子出生后两周内起个名字(需要办理 ...

  4. python 命令行升级pip

    import os import sys path = '"'+os.path.dirname(sys.executable)+'\\scripts\\pip" install - ...

  5. Jenkins + Ant + Jmeter 对项目的接口进行CI持续集成的配置 外加发送邮件 sendEmail

    Step1:安装Jenkins,从指定git上拉代码[安装步骤忽略] Step2:在项目安装的linux server上安装Ant 和Jmeter,我都安装在了自己的目录上,如下图 Step3:编写b ...

  6. [原][JSBSim]基于qt代码实现:TCP|UDP与飞行模拟软件JSBSim的通信,现实模型飞行!

    废话没有,上关键代码 头文件 #include <QUdpSocket> #include <qtcpsocket.h> #ifndef vrUDP #define vrUDP ...

  7. U3D协程yield的使用和理解

    部分内容参考网址:http://blog.csdn.net/huang9012/article/details/29595747 Win7+U3D 4.6.7 1.在c#中使用①首选需要定义一个返回值 ...

  8. 使用cocos创建的项目,如何进行源码调试?

    环境cocos3.10,里面包含了cocos2dx 3.10引擎.但是用cocos创建出来的项目,使用的lib和dll是文件夹Cocos\Cocos2d-x\cocos2d-x-3.10\prebui ...

  9. Codeforces 496D - Tennis Game

    496D - Tennis Game 思路:枚举每个t,求出对应的满足条件的s. 代码: #include<bits/stdc++.h> using namespace std; #def ...

  10. es6模块 nodejs模块和 typescript模块

    es6模块 import和export nodejs模块 require和module.exports typescript模块 module和export