I need to define a Date as an a @Input of a component:
<progress [start]="new Date()"></progress>
I get this error:
Parser Error: Unexpected token 'Date' at column 5 in [new Date()]
How to define a variable value when calling a component?
You cannot create/initialise and assign inside the attribute.
HTML
<progress [start]="getDate()"></progress>
Class
getDate(){
return new Date()
}
This said, you probably don't want to use it this way, as this way a new Date would be generated with the change detection. You might want to keep attribute's value in a property:
Class
myDate= new Date(); // This could be either on the top of the class, either in ngOnInit. Avoid putting in the constructor
HTML
<progress [start]="myDate"></progress>