I'm trying to use <mat-slide-toggle>Click me!</mat-slide-toggle>
inside a component which already has MatSlideToggleModule
imported, but I'm still getting the message that it's not a known element.
Angular version: 8.0.1
HTML Page (slide-page.html)
<div class="grid-slide-toggle-material">
<mat-slide-toggle>Click me!</mat-slide-toggle>
</div>
Module (slide-page.module.ts)
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MaterialModule } from 'projects/authenticator/src/shared/modules/material.module';
import { BasicModule } from 'src/app/shared/modules/basic/basic.module';
import { MatButtonToggleModule, MatButtonToggleGroup } from '@angular/material';
import { MatSlideToggleModule } from '@angular/material/slide-toggle';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
@NgModule({
declarations: [],
imports: [
MaterialModule,
ReactiveFormsModule,
CommonModule,
FormsModule,
MatButtonToggleModule,
MatSlideToggleModule
]
})
export class SlidePageModule { }
How is it possible that the html is not being recognized even after the imports in the item's module?
Slide toggle is created using MatSlideToggle Directive. The selector of MatSlideToggle is mat-slide-toggle . To create a slide toggle we use <mat-slide-toggle> element. MatSlideToggle provides input properties such as ariaLabel, ariaLabelledby, checked, color, disableRipple, disabled, id, labelPosition, name, required.
<mat-slide-toggle> is an on/off control that can be toggled via clicking. Basic slide-toggles. link code open_in_new. Slide me! The slide-toggle behaves similarly to a checkbox, though it does not support an indeterminate state like <mat-checkbox> .
The color of a <mat-slide-toggle> can be changed by using the color property. By default, slide-toggles use the theme's accent color. This can be changed to 'primary' or 'warn' .
As Daniel suggested, you need to add MatSlideToggleModule to your missing export in @NgModule.
But, please mind to write MatSlideToggleModule
instead of MatSlideToogleModule
.
In app.moudle.ts, add:
`import { MatSlideToggleModule } from '@angular/material/slide-toggle'`
inside @NgModule, imports, add:
MatSlideToggleModule
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With