angular - 如何在 Angular 中使用自定义管道覆盖默认的“异步”管道?
问题描述
我想做这样的事情:
import { AsyncPipe } from '@angular/common';
import { ChangeDetectorRef, Pipe } from '@angular/core';
import { PushPipe } from '@ngrx/component';
import { Observable } from 'rxjs';
@Pipe({
name: 'async'
})
export class AsyncPushPipe<T> extends AsyncPipe {
constructor(cdRef: ChangeDetectorRef, private pipe: PushPipe<T>) {
super(cdRef);
}
transform<T>(obj: Observable<T> | Promise<T>): T | null;
transform<T>(obj: null | undefined): null;
transform<T>(obj: Observable<T> | Promise<T> | null | undefined): T | null {
return this.pipe.transform(obj as any);
}
}
我将它添加到我的应用程序模块中,但似乎没有任何代码正在执行。PLATFORM_PIPES 在 Angular 2 中被弃用,这被认为是通过将代码添加到应用程序的 NgModule 来覆盖默认提供程序的方式。
有小费吗?
注意:我知道这是一种反模式,但我想在决定移动到推管是否是一个好主意之前进行一些测量。
解决方案
推荐阅读
- google-closure-compiler - Closure Compiler 同名的多个输出文件
- php - Wamp VS PHP:绝对正常且可访问的图像路径似乎已损坏
- sql - postgres中的字符串提取
- ibm-cloud - IBM Watson Assistant:聊天机器人实体混淆正则表达式 2
- php - Angular-如何在里面的图像中显示
标签 - c++ - 相同内容字符串文字的存储是否保证相同?
- javascript - 映射数组并在 javascript 中创建对象字面量
- typescript - TypeScript 中的“不可分配给类型参数从不”错误是什么?
- r - R 中的 Tesseract 无法识别同一文档中的较小字体
- julia - 将单个数字添加到 julia 数据框中的列?