#MatDatepicker: No provider found
54 messages · Page 1 of 1 (latest)
Please post your main.ts
You got to add one of the suggested provider functions to your bootstrapApplication method
I had the same issue and I added Date Module to app.module.ts und it worked. You might have a same scenario where you have a parent comp or something like that?
i dont have a app.modules.ts, i think because my components are standalone
im not sure what to do now
bootstrapApplication(AppComponent, {
providers: [provideNativeDateAdapter()]
})
.catch((err) => console.error(err));
now i cant see anything 😄
did you import provideNativeDateAdapter?
yes
import { appConfig } from './app/app.config';
import { AppComponent } from './app/app.component';
import { provideNativeDateAdapter } from '@angular/material/core';
bootstrapApplication(AppComponent, {
providers: [ provideNativeDateAdapter() ]
})
.catch((err) => console.error(err));
try to restart your app
Just put a repro on stackblitz
my full project?
my order folder is in app
on stackblitz in main.ts are errors, in my project not
Why did you use an Angular 6 base?
use this one https://stackblitz.com/edit/stackblitz-starters-b9vmyb?file=src%2Fmain.ts
i put my files in
do you have it in a public github repo?
Why?
im creating a repo on github moment
here is my add order component where i want to use the matdatepicker:
https://github.com/laurenz7/Commission/tree/main/Frontend/src/app/components/modules/order/add-order
Aside from missing @angular/cdk dependency it looks like basically working to me
https://stackblitz.com/edit/github-x4vpyg?file=src%2Fmain.ts,src%2Findex.html
in my project it doesnt work for me, got provider error when i open add order every time
retry now
btw, in the code you pushed on github there's not the provider I suggested earlier
when i click "+" button it doesnt open it, i think the same error like on my project
Because you didn't add the code I suggested for provider before pushing to github
i added it but deleted it before i push it to github
with ur provider code i see nothing
check on blitzstack
i changed the main.ts code to the new code with provider
idk if its changes with you too, if not paste that into main.ts:
import { appConfig } from './app/app.config';
import { AppComponent } from './app/app.component';
import { provideNativeDateAdapter } from '@angular/material/core';
bootstrapApplication(AppComponent, {
providers: [provideNativeDateAdapter()]
})
.catch((err) => console.error(err));
That's because you already had an appConfig in place
My edit was removing its reference, killing the stuff you were already providing
https://stackblitz.com/edit/github-x4vpyg?file=src%2Fmain.ts,src%2Findex.html,src%2Fstyles.scss,src%2Fapp%2Fapp.component.html,src%2Fapp%2Fapp.config.ts
yea it worked
thank u so much!!
@shell olive one question more, it is possible to change the format into DE format?
DD/MM/YYYY?
It's all in the docs.
Read it carefully, because you can do many things with date format and locale.
i read and tried it, but nothing changed.
on add-order.component.ts
import { MAT_DATE_LOCALE, MAT_DATE_FORMATS } from '@angular/material/core';
// Definiere deutsche Datumsformat
export const GERMAN_DATE_FORMATS = {
parse: {
dateInput: 'DD.MM.YYYY',
},
display: {
dateInput: 'DD.MM.YYYY',
monthYearLabel: 'MMM YYYY',
dateA11yLabel: 'DD.MM.YYYY',
monthYearA11yLabel: 'MMMM YYYY',
},
};
@Component({
selector: 'app-add-order',
standalone: true,
imports: [
MatCardModule,
MatFormFieldModule,
MatSelectModule,
MatIconModule,
MatButtonModule,
MatInputModule,
MatMenuModule,
MatPaginatorModule,
MatTableModule,
ReactiveFormsModule,
CommonModule,
MatDatepickerModule,
],
templateUrl: './add-order.component.html',
styleUrl: './add-order.component.scss',
providers: [
{ provide: MAT_DATE_LOCALE, useValue: 'de-DE' },
{ provide: MAT_DATE_FORMATS, useValue: GERMAN_DATE_FORMATS }
]
})
export class AddOrderComponent {