ionic g component <ComponentName>
——components |——ComponentName |——ComponentName.html |——ComponentName.scss |——ComponentName.ts |——components.module.ts
<div class="progress-outer"> <div class="progress-inner" [style.width]="progress +'%'"> {{showProgress}}% </div> </div>
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); } }
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'); } }
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 }) } }
<div (click)="MCClick()" class="red-text">from {{data}}</div>
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 {}
... 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/76355989css