I am trying to instantiate a DatePipe
object in my Angular2 app to use transform(...)
function in a component I'm developing.
// ...
import { DatePipe } from '@angular/common';
@Component({...})
export class PanelComponent implements OnInit {
// ...
datePipe: DatePipe = new DatePipe(); // Error thrown here
// ...
}
This code segment worked fine in RC5. Now I am trying to upgrade to Angular2 final release and getting this error when I run ng serve
or 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.
How can I resolve this issue? Is there another way of instantiating a Pipe? Or has Angular stopped supporting instantiating of Pipes inside components?
If you take a look at source code then you will see that DatePipe constructor asks for a required parameter:
There is no default locale for DataPipe
https://github.com/angular/angular/blob/2.0.0/modules/%40angular/common/src/pipes/date_pipe.ts#L97
That's why typescript gives the error. This way you have to initiate your variable as shown below:
Hope it helps you!
looks everything fine, error must be anywhere else in your code. See my plunker: https://plnkr.co/edit/koDu6YmB131E6sXc6rKg?p=preview
And @Harry Ninh .. you can't inject Pipes!!