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. 二维数组模拟实现酒店管理系统-java

    业务分析 1.需要一个房间类,包含房间的属性,比如房间编号.房间类型.是否占用. 2.需要一个旅馆类,旅馆有房间,提供的方法需要有 预订房间.打印房间信息.初始化房间.退房. 3.测试类,测试预订房间 ...

  2. tp5命名空间

  3. geotools实现多边形的合并&缓冲区

    这算是第一次接触开源工具包,说实话刚开始有点不知所措,中途遇到很多问题的时候也感觉头皮发麻,不过很高兴自己还是坚持下来了. geotools就不做过多的介绍了,想总结一下如何根据开源内容做自己的项目. ...

  4. (Release Candidate)Candidate

    RC:(Release Candidate)Candidate是候选人的意思,用在软件或者操作系统上就是候选版本

  5. 在Word2010文档中显示域代码而非域值

    当Word2010文档中含有域内容时,默认情况下显示域值,这样可以使插入的域内容清晰明了.用户可以根据需要选择显示域代码或显示域值,操作步骤如下所述: 步骤/方法 第1步,打开Word2010文档窗口 ...

  6. Jpa 本地方式实现数据的持久化【千锋】

    Jpa本身支持多种方式的对象持久化,比如数据库方式,还有一种方式就是本地文件的方式,本文来讲解以本地方式实现的数据持久化,具体的资源大家可以参阅一下网站:http://www.objectdb.com ...

  7. ASP.net core 2.0.0 中 asp.net identity 2.0.0 的基本使用(一)—修改数据库连接

    开发环境:vs2017  版本:15.3.5 项目环境:.net framework 4.6.1    模板asp.net core 2.0  Web应用程序(模型视图控制器) 身份验证:个人用户账号 ...

  8. 【转】WPF 从FlowDocument中找到Hyperlink

    原文地址:How can I get a FlowDocument Hyperlink to launch browser and go to URL in a WPF app? #region Ac ...

  9. junit设计模式--适配器模式

    适配器(Adapter)模式 在软件系统中,由于环境的变化,常常需要将"一些现存的对象"放在新的环境中应用,但是新环境要求的接口是这些现存对象所不满足的.那么如何应对这种" ...

  10. 输入和输出--File类

    输入和输出 写在前面的:Java中的输入和输出还是比较重要的,之前我都没想整理IO和多线程的,但是在研究后面的好多东西时候,经常要读取资源文件,这个时候就不得不回过头来整理IO了.要玩熟Java的输入 ...