角2使用管道服务 [英] Angular 2 use pipes in services
本文介绍了角2使用管道服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在角1我能够使用过滤器(管道)内使用类似于此语法服务和控制器:
In Angular 1 I am able to use filters (pipes) inside of services and controllers using syntax similar to this:
$filter('date')(myDate, 'yyyy-MM-dd');
是否有可能在角2使用管道服务/组件这样?
Is it possible to use pipes in services/components like this in Angular 2?
推荐答案
您应该能够直接使用类
new DatePipe().transform(myDate, ['yyyy-MM-dd']);
例如
var raw = new Date(2015, 1, 12);
var formatted = new DatePipe().transform(raw, ['yyyy-MM-dd']);
expect(formatted).toEqual('2015-02-12');
这篇关于角2使用管道服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文