【发布时间】:2017-01-29 04:10:05
【问题描述】:
我正在尝试在我的 Angular2 应用程序中实例化一个 DatePipe 对象,以便在我正在开发的组件中使用 transform(...) 函数。
// ...
import { DatePipe } from '@angular/common';
@Component({...})
export class PanelComponent implements OnInit {
// ...
datePipe: DatePipe = new DatePipe(); // Error thrown here
// ...
}
此代码段在 RC5 中运行良好。现在我正在尝试升级到 Angular2 最终版本并在运行 ng serve 或 ng build 时收到此错误,
~/tmp/broccoli_type_script_compiler-input_base_path-XitPWaey.tmp/0/src/app/panel/panel.component.ts (33, 24):
Supplied parameters do not match any signature of call target.
我该如何解决这个问题?还有另一种实例化管道的方法吗?还是 Angular 已经停止支持在组件内实例化管道?
【问题讨论】:
-
您只是以错误的方式使用管道。您不应该手动实例化管道,而是使用 DI。
标签: angular angular2-pipe