Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'mat-slide-toggle' is not a known element after import

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?

like image 863
MattDAVM Avatar asked Mar 10 '20 14:03

MattDAVM


People also ask

How do you set the slide toggle mat value?

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.

What is mat-slide-toggle?

<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> .

How to change color of mat-slide-toggle?

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' .


1 Answers

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 
like image 154
Hila Grossbard Avatar answered Sep 20 '22 08:09

Hila Grossbard