• Angular自定义管道


    1.alarm-piple.piple.ts

    import { Pipe, PipeTransform } from '@angular/core';
    
    @Pipe({
        name: 'alarmPipe'
    })
    export class AlarmPipePipe implements PipeTransform {
        transform(value: any, args?: any): any {
            let res: string;
            if (value === 1) {
                res = 'TRUE';
            } else if (value === 0) {
                res = 'FALSE';
            } else if (value === -1) {
                res = 'UNVERIFIED';
            } else {
                res = 'OPEN';
            }
            return res;
        }
    }
    
    @Pipe({
        name: 'eqtAlarm'
    })
    export class EqtAlarmPipe implements PipeTransform {
        transform(value: string): string {
            let res: string;
            if (value === 'CF') {
                res = 'Constant Fault(Hardware Failure)';
            } else if (value === 'IF') {
                res = 'Intermittent Fault';
            } else {
                res = value;
            }
            return res;
        }
    }
    
    
    

    2.piple.module.ts

    import { NgModule } from '@angular/core';
    import { AlarmPipePipe, EqtAlarmPipe} from 'app/alarm-management/alarm-pipe.pipe';
    const PIPES = [AlarmPipePipe, EqtAlarmPipe];
    
    @NgModule({
        declarations: PIPES,
        exports: PIPES
    })
    export class AlarmPipesModule {}
    
    

    3.在需要使用的组件对应的module中引入

    // example.module.ts
    
    import { NgModule } from '@angular/core';
    import { NgZorroAntdModule } from 'ng-zorro-antd';
    import { MaterialModule } from 'app/shared/material/material.module';
    import { FormsModule } from '@angular/forms';
    import { SharedModule } from 'app/shared';
    import { TranslateModule } from '@ngx-translate/core';
    import { AlarmPipesModule } from 'app/alarm-management/alarm-pipes.module';
    import { EquipmentAlarmDetailsComponent } from 'app/alarm-management/equipment-alarm-details/equipment-alarm-details.component';
    
    const COMPONENTS = [EquipmentAlarmDetailsComponent];
    @NgModule({
        imports: [NgZorroAntdModule, MaterialModule, FormsModule, SharedModule, TranslateModule, AlarmPipesModule],
        declarations: COMPONENTS,
        exports: COMPONENTS
    })
    export class EqtAlarmDetailsModule {}
    
    

    4.模板中使用

     <span>{{detailItem?.alarmType | eqtAlarm}}</span>
     <span>{{detailItem?.isGenuine | alarmPipe | titlecase}}</span>
    
  • 相关阅读:
    Oracle 手工清除回滚段的几种方法
    Oracle dump undo 说明
    Oracle ORA_ROWSCN 伪列 说明
    Oracle 10.2.0.4 高负载 触发 ORA00494 错误
    Oracle Block scn/commit scn/cleanout scn 说明
    Oracle 游标(cursor) 说明
    Oracle 10g Toad查看 表空间 报错 ORA00600 internal error code arguments [ktfbhget4], [6], [5]
    Oracle Block scn/commit scn/cleanout scn 说明
    Oracle 监听(Listener) 中 services 说明
    Oracle 游标(cursor) 说明
  • 原文地址:https://www.cnblogs.com/yuanchao-blog/p/13524554.html
Copyright © 2020-2023  润新知