相关疑难解决方法(0)

Angular - 在服务和组件中使用管道

在AngularJS中,我能够使用类似于此的语法在服务和控制器内部使用过滤器(管道):

$filter('date')(myDate, 'yyyy-MM-dd');
Run Code Online (Sandbox Code Playgroud)

是否可以在Angular中使用像这样的服务/组件中的管道?

angular

306
推荐指数
8
解决办法
21万
查看次数

在angular2上的自定义管道上扩展管道,如货币或数字

我想在我的自定义管道上调用numberPipe,我找到了这个答案

Angular2在自定义管道中使用基本管道

但我这个解决方案对我不起作用.我有一个错误"无法找到管道'bigInteger'"

import { Pipe, PipeTransform } from "@angular/core"
import { CurrencyPipe  } from "@angular/common"

@Pipe({
 name: "bigInteger"
 })
 export class BigInteger extends CurrencyPipe implements PipeTransform {
   transform(value: any): string {
    return value
 }
}
Run Code Online (Sandbox Code Playgroud)

pipe typescript angular

11
推荐指数
2
解决办法
7300
查看次数

Angular 2 - 如何在自定义管道内使用内置管道

我想使用内置货币管道制作自定义货币管道。我想要使​​用的方式是{{ anyNumber | customCurrency }}.然后在我的自定义货币管道中,我想使用内置货币管道。我可以根据某些逻辑决定货币管道的参数,并且不想像{{anyNumber | currency:'USD':false:'1:0-0'}}.

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'customCurrency'
})
export class CustomCurrencyPipe implements PipeTransform {

  transform(value: any, args?: any): any {
      const defaultLocale = 'USD';
      const showSymbol = false;

      ......some logic here......      

      //HOW TO USE CURRENCY PIPE HERE?

 }

}
Run Code Online (Sandbox Code Playgroud)

angular-pipe angular2-custom-pipes angular

5
推荐指数
1
解决办法
1万
查看次数