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. UVa 10382 喷水装置(贪心)

    https://vjudge.net/problem/UVA-10382 题意: 有一个长为l,宽为w的草坪,在其中心线不同位置有n个点状的喷水装置,喷水坐标为p,喷水半径为r.求喷到所有草坪的最少喷 ...

  2. UVa 10118 免费糖果(记忆化搜索+哈希)

    https://vjudge.net/problem/UVA-10118 题意: 桌上有4堆糖果,每堆有N颗.佳佳有一个最多可以装5颗糖的小篮子.他每次选择一堆糖果,把最顶上的一颗拿到篮子里.如果篮子 ...

  3. 深蓝色 --ppt

    Deep Learning of Binary Hash Codes for Fast Image Retrieval [Paper] [Code-Caffe] 1. 摘要 针对图像检索问题,提出简单 ...

  4. React native 的DatePickerIOS组件

    1.首先如代码所示  引入DatePickerIOS组件 设置他的时间是当前时间 export default class AlertDemo extends Component { render() ...

  5. TDD、BDD、DDD

    TDDTest-Driven DevelopmentTest-Driven Development (TDD) is a software development technique where au ...

  6. Thunder团队项目视频展示

    视频链接:http://v.youku.com/v_show/id_XMzA5MjMzMzcyMA==.html?spm=a2h3j.8428770.3416059.1 视频简介:通过一个小情景开篇, ...

  7. [Java学习] Java虚拟机(JVM)以及跨平台原理

    相信大家已经了解到Java具有跨平台的特性,可以“一次编译,到处运行”,在Windows下编写的程序,无需任何修改就可以在Linux下运行,这是C和C++很难做到的. 那么,跨平台是怎样实现的呢?这就 ...

  8. 4-4 集成测试练习,和测试基础知识(guide)。

    Guide指南 18章应用测试指南(简单学习了一下.) (中文版--主要是为了先理解,之前看过英文版受语言影响,怕理解有偏差.) Minitest::Test是ActiveSupport::TestC ...

  9. Dynamic Web Module 3.1 requires Java 1.7 or newer. 错误解决方案

    在写代码的时候工程出现了这样奇怪的bug很是蛋疼啊,经过查询解决方法,终于解决了这些个问题. 下面是解决问题的方法,和大家分享一下 (1)确定你的java工程配置使用了java 7 右键单击你的工程p ...

  10. 『Sklearn』数据划分方法

    原理介绍 K折交叉验证: KFold,GroupKFold,StratifiedKFold, 留一法: LeaveOneGroupOut,LeavePGroupsOut,LeaveOneOut,Lea ...