1-在html文件中使用管道;(管道符合使用,用‘’号隔开)

①页面中添加;

 <div class="table_content" *ngFor="let item of result">
<div class="col1">{{item.DESC}}</div>
<div class="col2" *ngIf="item.DATA">{{item.DATA}}</div>
<div class="col3" *ngIf="item.ZB">{{item.ZB | decimal2:'%'}}</div>
</div>

②完成依赖注入;

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { ReportCheckResultPage } from './report-check-result';
import { PipesModule } from '../../../../pipes/pipes.module'; @NgModule({
declarations: [
ReportCheckResultPage,
],
imports: [
PipesModule,
IonicPageModule.forChild(ReportCheckResultPage),
],
exports: [
ReportCheckResultPage
],
})
export class ReportCheckResultPageModule {}
pipes.module.ts
import { NgModule } from '@angular/core';
import { Decimal2Pipe } from './decimal2/decimal2';
@NgModule({
declarations: [Decimal2Pipe,],
imports: [],
exports: [Decimal2Pipe,]
})
export class PipesModule {}


2-在.ts文件中使用管道;

①导入相应文件;

import { ChinesePipe } from '../../../../pipes/chinese/chinese';//导入相应管道文件;
@IonicPage({
name: 'reportCheck',
segment: 'reportCheck'
})
@Component({
selector: 'page-report-check',
templateUrl: 'report-check.html',
})
export class ReportCheckPage {
constructor(
public navCtrl: NavController,
public navParams: NavParams,
public cp: ChinesePipe,
) {} formatFun(){
return this.cp.transform(key,res[key]);
}

②完成依赖注入;

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { ReportCheckPage } from './report-check';
import { ChinesePipe } from '../../../../pipes/chinese/chinese'; @NgModule({
declarations: [
ReportCheckPage,
],
imports: [
IonicPageModule.forChild(ReportCheckPage),
],
exports: [
ReportCheckPage
],
providers:[ChinesePipe]
})
export class ReportCheckPageModule {}

Angular Pipe的应用的更多相关文章

  1. Angular 利用 marked.js 添加 Markdown + HTML 同时渲染的 Pipe

    背景 最近在公司开发的一个项目需要在 Angular 上展示图文,并且需要同时支持 Markdown 和 HTML 对于同时支持 Markdown 和 HTML ,应该要分为编辑和渲染两部分考虑. 对 ...

  2. 如何解决angular不自动生成spec.ts文件

    "schematics":{   "@schematics/angular:component": {        "styleext": ...

  3. [转]VS Code 扩展 Angular 6 Snippets - TypeScript, Html, Angular Material, ngRx, RxJS & Flex Layout

    本文转自:https://marketplace.visualstudio.com/items?itemName=Mikael.Angular-BeastCode VSCode Angular Typ ...

  4. Angular 6.X CLI(Angular.json) 属性详解

    Angular CLI(Angular.json) 属性详解 简介 angular cli 是angular commond line interface的缩写,意为angular的命令行接口.在an ...

  5. ng 基础

    文档 组件的工作只管用户体验,而不用顾及其它. 它应该提供用于数据绑定的属性和方法,以便作为视图和应用逻辑的中介者 组件应该把诸如从服务器获取数据.验证用户输入或直接往控制台中写日志等工作委托给各种服 ...

  6. [Angular 2] Understanding Pure & Impure pipe

    First, how to use a build in pipe: <div class="pipe-example"> <label>Uppercase ...

  7. [Angular 2] Rendering an Observable with the Async Pipe

    Angular 2 templates use a special Async pipe to be able to render out Observables. This lesson cover ...

  8. [Angular] Increasing Performance by using Pipe

    For example you make a function to get rating; getRating(score: number): string { let rating: string ...

  9. [Angular] Bind async requests in your Angular template with the async pipe and the "as" keyword

    Angular allows us to conveniently use the async pipe to automatically register to RxJS observables a ...

随机推荐

  1. LitePal 之 DatabaseGenerateException

    DatabaseGenerateException错误 出现这个错误,是因为表结构的实体类中的属性(对应数据库中的字段) 与 SQL语法中的关键字冲突 . 另外 记录一下 配置litepal.xml文 ...

  2. input事件中文触发多次问题研究

    我们在网页中经常会遇到实时搜索的情况,或者其他类似需要input实时响应的问题,一般情况下,我们是利用input和propertychange事件来监听input内容的变化来响应,但是有一个问题就是当 ...

  3. alert一般用来调试客户端的javascript代码,以及更好的调试方法

    alert一般用来调试客户端的javascript代码 调试利器--console.log 如今主流浏览器(Chrome,IE8及后续版本,FireFox,Opera等)都支持控制台功能. Chrom ...

  4. 基于 HTML5 WebGL 的 3D 仪表数据监控

    工控仪表重点发展基于现场总线技术的主控系统装置及智能化仪表.特种和专用自动化仪表:全面扩大服务领域,推进仪器仪表系统的数字化.智能化.网络化,完成 自动化仪表从模拟技术向数字技术的转变:推进具有自主版 ...

  5. Java XML 序列化和反序列化

    Utils 类: import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileWr ...

  6. isinstance和issubclass、动态模块导入、异常处理

    一.isinstance和issubclass isinstance:判断某个对象是否是某个类的实例,返回True或Flase issubclass:判断某个类是否是某个类的子类. 例如: class ...

  7. es7重点笔记

    1,函数绑定运算符,用来取代call,apply,bind调用,写法:并排的双冒号(::),左边是对象,右边是函数 foo :: bar; // 等同于bar.bind(foo); 双冒号返回的还是原 ...

  8. Redis-配置认证密码

    1.找到redis.conf,配置密码 2.要重新启动一下redis 3.用redis-cli重新登陆,我们查询的时候提示"Authentication required"查询失败 ...

  9. apache日志管理【转】

    web服务器日志轮循比较好的方式有三种:第一种方法是利用Linux系统自身的日志文件轮循机制:logrotate:第二种方法是利用apache自带的日志轮循程序rotatelogs:第三种是使用在ap ...

  10. Redis集群方案怎么做?大牛给你介绍五种方案!

    Redis集群方案 Redis数据量日益增大,而且使用的公司越来越多,不仅用于做缓存,同时趋向于存储这块,这样必促使集群的发展,各个公司也在收集适合自己的集群方案,目前行业用的比较多的是下面几种集群架 ...