angular material calendar not showing properly - html

this is the html code i wrote
<mat-form-field appearance="fill">
<mat-label>Enter a date range</mat-label>
<mat-date-range-input [rangePicker]="picker">
<input matStartDate placeholder="Start date">
<input matEndDate placeholder="End date">
</mat-date-range-input>
<mat-hint>MM/DD/YYYY – MM/DD/YYYY</mat-hint>
<mat-datepicker-toggle matIconSuffix [for]="picker"></mat-datepicker-toggle>
<mat-date-range-picker #picker></mat-date-range-picker>
</mat-form-field>
styles.css
#import "~#angular/material/prebuilt-themes/deeppurple-amber.css";
app.module.ts code
note : i didnt show all the imports i wrote
import { BrowserAnimationsModule } from '#angular/platform-browser/animations';
import {MatDatepickerModule} from '#angular/material/datepicker'
import {MatInputModule} from '#angular/material/input'
import {MatFormFieldModule} from '#angular/material/form-field'
import { MatNativeDateModule } from '#angular/material/core';
#NgModule({
declarations: [
AppComponent,
LoginComponent,
HeaderComponent,
FooterComponent,
LogoutComponent,
ActualteComponent,
ForumComponent,
AgendaComponent
],
imports: [
BrowserModule,
AppRoutingModule,
FormsModule,
HttpClientModule,
BrowserAnimationsModule,
MatDatepickerModule,
MatInputModule,
MatFormFieldModule,
MatNativeDateModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
this is the output
i used the code from the official angular material website and its like
this

I too had some issues when using the mat-date picker component from angular here's what i did
I used the same html code you posted
Added Angular material using ng add #angular/material
I had to import some more modules other than the date picker module as i encountered some errors. Here's my app.module.ts
import { NgModule } from '#angular/core';
import { CommonModule } from '#angular/common';
import { MatDatepickerModule } from '#angular/material/datepicker';
import { MatFormFieldModule } from '#angular/material/form-field';
import { MatInputModule } from '#angular/material/input';
import { AppComponent } from './app.component';
import { BrowserModule } from '#angular/platform-browser';
import {MatNativeDateModule} from '#angular/material/core';
import { BrowserAnimationsModule } from '#angular/platform-browser/animations';
#NgModule({
declarations: [
AppComponent
],
imports: [
BrowserAnimationsModule,
MatNativeDateModule,
BrowserModule,
CommonModule,
MatDatepickerModule,
MatFormFieldModule,
MatInputModule,
],
exports: [
MatDatepickerModule,
MatFormFieldModule,
MatInputModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
I restarted the app and ran it and it worked fine for me.
I didn't have to do the import for the deep purple theme as it showed the option to select one when adding the angular material.
My Angular version is Angular: 15.1.5 and the material version is "#angular/material": "^15.1.5",

Related

'mat-toolbar' is not a known element

I used in app.component.html :
<mat-toolbar>
Responsive side navigation
</mat-toolbar>
and I define MatToolbarModule in app.module.ts
import { NgModule } from '#angular/core';
import { BrowserModule } from '#angular/platform-browser';
import { AppRoutingModule } from './app-routing/app-routing.module';
import { BrowserAnimationsModule } from '#angular/platform-browser/animations';
import { MatToolbarModule } from '#angular/material/toolbar';
import { AppComponent } from './app.component';
#NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
BrowserAnimationsModule,
MatToolbarModule,
MatSidenavModule,
MatButtonModule,
MatIconModule,
MatDividerModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
I obtain this error when I execute ng build command:
Error: src/app/app.component.html:1:1 - error NG8001: 'mat-toolbar' is not a known element:
1. If 'mat-toolbar' is an Angular component, then verify that it is part of this module.
2. If 'mat-toolbar' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '#NgModule.schemas' of this component to suppress this message.
please, how to correct this error
Based on what you shared (before any update) your set up is sufficient to make it working. In case you are on VSCode closing and opening the IDE would be sufficient sometimes to get ride of this kind of compilation errors.
Here is a stackblitz compatible with your code above works fine.

how to solve 'mat-list-option' is an Angular component?

I have tried everything on the internet and nothing seems to fix my error.
this is my NgModule :
import { BrowserModule } from '#angular/platform-browser';
import { NgModule } from '#angular/core';
import { BrowserAnimationsModule } from '#angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { MDBBootstrapModule } from 'angular-bootstrap-md';
import { FormsModule } from '#angular/forms';
import { MainLayoutComponent } from './MainLayout/main-layout/main-layout.component';
import { AppRoutingModule } from './app-routing.module';
import { ContainersPageComponent } from './Containers/containers-page/containers-page.component';
import { HttpClientModule } from '#angular/common/http';
import { MatTableModule } from '#angular/material/table';
import { MarinServiceService } from './services/marin-service.service';
import { MatPaginatorModule, MatSortModule, MatInputModule, MatSelectModule, MatFormFieldModule } from '#angular/material';
#NgModule({
declarations: [
AppComponent,
MainLayoutComponent,
ContainersPageComponent,
],
imports: [
BrowserModule,
BrowserAnimationsModule,
MDBBootstrapModule.forRoot(),
FormsModule,
AppRoutingModule,
HttpClientModule,
MatTableModule,
MatPaginatorModule,
MatSortModule,
MatInputModule,
MatSelectModule,
MatFormFieldModule,
],
providers: [MarinServiceService],
bootstrap: [AppComponent]
})
export class AppModule { }
This is the exact Error im getting :
)
: 'mat-selection-list' is not a known element:
1. If 'mat-selection-list' is an Angular component, then verify that it is part of this module.
2. If 'mat-selection-list' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '#NgModule.schemas' of this component to suppress this message. ("
<!--Check Box Search-->
[ERROR ->]<mat-selection-list >
<mat-list-option >
I have tried re-Importing and it didn't work.
I have tried importing everything Mat related.
I really don't know what seems to be the problem.
You need to import MatListModule
import {MatListModule} from '#angular/material/list';
Add it under imports array of the app.module.ts
You need to import Mat List Module in the concerned module.
import {MatListModule} from '#angular/material/list';
More information: https://material.angular.io/components/list/api

Errors with <mat-form-field>. Normal Input works fine, but cant use mat-select with out an error

I've had a look at other questions yet none have yielded results.
<mat-form-field>
<mat-select matInput placeholder="Favorite food">
<mat-option *ngFor="let food of foods" [value]="food.value">
{{food.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>
Basic selector. I get this error when I run in browser.
If 'mat-option' is an Angular component and it has 'value' input, then verify that it is part of this module.
If 'mat-option' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '#NgModule.schemas' of this component to suppress this
Had a look around and i've imported the api needed.
import { MatFormFieldModule } from '#angular/material/form-field';
import {MatSelectModule} from '#angular/material/select'
I also have alot of other Mat Imports
import {
MatInputModule,
MatMenuModule,
MatCardModule,
MatButtonModule,
MatIconModule,
MatToolbarModule,
MatExpansionModule,
} from '#angular/material';
Yet I'm still getting the error. App working completely fine with regular input such as:
<mat-form-field>
<mat-label>Address</mat-label>
<input placeholder="eg 221B Baker Street" type="text"
name="Address" ngModel required minlength="5" #title="ngModel">
</mat-form-field>
Been on this for a day and its a point where I cant progress without fixing it. Any help will be appreciated.
I wont be able to reply until i get from work.
thanks again!
Edit: Adding In the entire app.module.ts
import { BrowserModule } from '#angular/platform-browser';
import { NgModule } from '#angular/core';
import { AppComponent } from './app.component';
import { PostDetailsComponent } from './post-details/post- details.component';
import { PostService } from './services/post.service';
import { HttpClientModule } from '#angular/common/http';
import { BrowserAnimationsModule } from '#angular/platform-browser/animations';
import { RouterModule, Routes } from '#angular/router';
import { FormsModule } from "#angular/forms";
import {
MatInputModule,
MatMenuModule,
MatCardModule,
MatButtonModule,
MatIconModule,
MatToolbarModule,
MatExpansionModule,
} from '#angular/material';
import { MatFormFieldModule } from '#angular/material';
import {MatSelectModule} from '#angular/material'
import { PostCreateComponent } from './post-create/post-create.component';
import { PostEditComponent } from './post-edit/post-edit.component';
import { PostSigninComponent } from './post-signin/post-signin.component';
import { MembershipTypesComponent } from './membership-types/membership- types.component';
const appRoutes: Routes = [
{
path: 'list',
component: PostDetailsComponent
},
{
path: 'create',
component: PostCreateComponent
},
{
path: 'edit/:id',
component: PostEditComponent
},
{
path: 'membershipTypes',
component: MembershipTypesComponent
}
];
#NgModule({
declarations: [
AppComponent,
PostDetailsComponent,
PostCreateComponent,
PostEditComponent,
PostSigninComponent,
MembershipTypesComponent
],
imports: [
RouterModule.forRoot(appRoutes),
BrowserModule,
FormsModule,
HttpClientModule,
MatIconModule,
MatButtonModule,
BrowserAnimationsModule,
MatInputModule,
MatFormFieldModule,
MatCardModule,
MatButtonModule,
MatToolbarModule,
MatExpansionModule,
MatMenuModule,
],
providers: [PostService],
bootstrap: [AppComponent]
})
export class AppModule { }
You need to add MatSelectModule into the imports array, like so:
imports: [
RouterModule.forRoot(appRoutes),
BrowserModule,
FormsModule,
HttpClientModule,
MatIconModule,
MatButtonModule,
BrowserAnimationsModule,
MatInputModule,
MatFormFieldModule,
MatCardModule,
MatButtonModule,
MatToolbarModule,
MatExpansionModule,
MatMenuModule,
MatSelectModule
],
you are importing MatSelectModule in wrong way, just try:
import {MatSelectModule} from '#angular/material'

Prosemirror editor tool bar incomplete on Angular 6

I have integrated ProseMirror in my Angular 6 as a text editor using Directives as below:
import { BrowserModule } from '#angular/platform-browser';
import { NgModule, Injector } from '#angular/core';
import { ProsemirrorModule } from './prosemirror/prosemirror.module';
import { BrowserAnimationsModule } from '#angular/platform-browser/animations';
import { MatButtonModule, MatCardModule, MatInputModule } from '#angular/material';
#NgModule({
declarations: [
AppComponent,
MyElementComponent
],
imports: [
BrowserModule,
ProsemirrorModule,
BrowserAnimationsModule,
MatButtonModule,
MatCardModule,
MatInputModule
],
providers: [],
})
export class AppModule {
}
ngDoBootstrap() {
}
}
and used html as:
<div appEditor></div>
all are working well...but toolbar does not appear properly...all aligned one below other
No idea how to make it to appear properly. Any help please

after using CUSTOM_ELEMENTS_SCHEMA custom tag's content still not visible

I have this scenario: there are three modules, header.module, _shared.module and app.module.
header.module imports and exports the header component. _shared.module acts as a wrapper module and imports the header.module. app.module finally imports the _shared.module.
Finally i am using the header through it's selector eg <dir-header> in app.component.html. I have even included CUSTOM_ELEMENTS_SCHEMA in app.module to suppress any error that may arise. But i'm no longer able to see the header, although the tag <dir-header></dir-header> is there in DOM, but it's content <div class="..." >...</div> is not.
header.module :-
import { NgModule } from '#angular/core';
import { CommonModule } from '#angular/common';
import { FormsModule, ReactiveFormsModule } from '#angular/forms';
import { HeaderComponent } from './header.component';
import { HeaderRoutingModule } from './header-routing.module';
#NgModule({
declarations: [
HeaderComponent
],
imports: [HeaderRoutingModule, ReactiveFormsModule, CommonModule],
exports: [
HeaderComponent
]
})
export class HeaderModule {}
_shared.module :-
import { HeaderModule } from './header/header.module';
import { FooterModule } from './footer/footer.module';
#NgModule({
imports: [
CommonModule,
FormsModule,
HeaderModule,
FooterModule
],
declarations: [],
exports: []
})
export class SharedModule {}
app.module :-
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '#angular/core';
/*rest of the code*/
#NgModule({
declarations: [
AppComponent,
PageNotFoundComponent
],
schemas: [ CUSTOM_ELEMENTS_SCHEMA ],
imports:
[...
SharedModule,
...
],
providers: [CrudService, ...],
bootstrap: [AppComponent]
})
export class AppModule { }
EDIT: It is not importing the <header-dir> from header.module rather creating a new custom selector in app.component.html. How do I import the header from header.module ?
[ISSUE SOLVED] first of all, remove the CUSTOM_ELEMENTS_SCHEMA from app.module because it is not really required in THIS case. Next, in _shared.module under the exports section, also export the custom modules you have imported here i.e. header.module and foot.module :-
_shared.module
import { NgModule} from '#angular/core';
import { CommonModule } from '#angular/common';
import { FormsModule } from '#angular/forms';
import { HeaderModule } from './header/header.module';
import { FooterModule } from './footer/footer.module';
#NgModule({
imports: [
CommonModule,
FormsModule,
HeaderModule,
FooterModule
],
declarations: [],
exports: [HeaderModule,
FooterModule]
})
export class SharedModule {}