Open jakehockey10 opened 4 years ago
Hey @jakehockey10, I was facing the same issue, which can be solved by short-circuiting the (strict) type checker:
@Component({
template: `
<input matInput [ngxMatDatetimePicker]="ngxMatDatetimePicker">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<ngx-mat-datetime-picker #ngxMatDatetimePicker></ngx-mat-datetime-picker>
`
})
export class ExampleComponent {
@ViewChild(NgxMatDatetimePicker)
public picker?: MatDatepicker<Date>;
}
This will let Your project compile, but at runtime You will be confronted by https://github.com/h2qutc/angular-material-components/issues/65#issuecomment-667768132 or https://github.com/h2qutc/angular-material-components/issues/89.
I guess the cause of #65 and #89 are the @angular/material^10.0.0
changes around the new DateRangePicker. The MatDatepicker now extends MatDatepickerBase, which (I guess) NgxMatDatetimePicker should do to. But I'm not sure, just skimmed the code a bit .. :)
HI @schlusslicht , yes you're right The MatDatepicker they now extend MatDatepickerBase but the problem still not solve by using ViewChild and picket in component ts file, so any other work around for this
@imvikaskohli Hey, if you've updated to version 4.0.3 of the package then all you have to do apart from @schlusslicht 's change is adding {static: true} in the ViewChild decorator.
@ViewChild(NgxMatDatetimePicker, { static: true }) public picker?: MatDatepicker<Date>;
Also, try using a different identifier for [ngxMatDatetimepicker]
and [for]
(ngxMatDatetimePicker
and picker
) like @schlusslicht did, that did made it work eventually but I would like to know the reason behind that :)
@highyerbuoy as the #ngxMatDatetimePicker
statement already creates a (template reference) variable, You have to use another name for the variable from within the component. If You use the same variable names for both, the public component variable and the template reference variable, the template reference variable overrides the one from the component (at least within the template).
As for the { static: true }
part of Your comment, I think it should work without specifying this param to the @ViewChild
decorator, but this might depend on the context - at least for me it's working without the static
param.
My Angular version:
The error I'm getting:
I'd like to keep my strict settings intact in tsconfig.base.json. Does this library just need an update? Or did I do something wrong?