angular - mat-slide-toggle is not visible

后端 未结 1 874
难免孤独
难免孤独 2021-01-13 03:39

problem

mat-slide-toggle is not visible.

I\'m trying to implement this example from below url https://material.angular.io/compon

1条回答
  •  逝去的感伤
    2021-01-13 04:24

    In your module definition you forgot to add MatSlideToggleModule (you are importing the file but your app doesn't use it) in the imports section and you need BrowserAnimationsModule:

    @NgModule({
    declarations: [
        AppComponent,
        HeroDetailComponent,
        HeroesComponent,
        DashboardComponent,
        HeroSearchComponent,
        MaterialDashboardComponent,
        UserComponent,
        LoginComponent,
        AlertComponent,
        RegisterComponent,
        HomeComponent,
        ApiDashboardComponent,
        ApiDashboardformComponent,
        EditApiDashboardComponent,
        MaterialThemeComponent,
        LoginFosUserandRestBundleComponent,
        LoginuserbundleComponent,
        MaterialTestthemeComponent
    
        //MenuIconsExample
        //AppRoutingModule
    ],
    
    imports: [
        BrowserModule,
        FormsModule,
        HttpModule,
        RouterTestingModule,
        InMemoryWebApiModule.forRoot(InMemoryDataService, { passThruUnknownUrl: true }), // fake in memory API simulation
        // InMemoryWebApiModule.forRoot(InMemoryDataService),
        AppRoutingModule,
        MatSidenavModule,
        MatInputModule,
        MatMenuModule,
        BrowserAnimationsModule,
        MatTableModule,
        CdkTableModule,
        DataTablesModule,
        //MaterialModule,
        ReactiveFormsModule,
        MatAutocompleteModule,
        MatFormFieldModule,
        MatSlideToggleModule, // here otherwise it's not possible to use the component mat-slide-toggle defined in this module
        BrowserAnimationsModule
    ],
    //exports: [MatSidenavModule,MatInputModule,MatMenuModule],
    exports: [
        CdkTableModule,
        MatAutocompleteModule,
        MatButtonModule,
        MatButtonToggleModule,
        MatCardModule,
        MatCheckboxModule,
        MatChipsModule,
        //MatCoreModule,
        MatDatepickerModule,
        MatDialogModule,
        MatExpansionModule,
        MatGridListModule,
        MatIconModule,
        MatInputModule,
        MatListModule,
        MatMenuModule,
        MatNativeDateModule,
        MatPaginatorModule,
        MatProgressBarModule,
        MatProgressSpinnerModule,
        MatRadioModule,
        MatRippleModule,
        MatSelectModule,
        MatSidenavModule,
        MatSliderModule,
        MatSlideToggleModule,
        MatSnackBarModule,
        MatSortModule,
        MatTableModule,
        MatTabsModule,
        MatToolbarModule,
        MatTooltipModule,
    ],
    schemas: [CUSTOM_ELEMENTS_SCHEMA],
    //declare your service  here 
    providers: [HeroService, UserService, AlertService, AuthGuard,
    
        AuthenticationService,
        UserService,
        ApiDashboard,
        ApiDashboardDataService,
        FormService,
        UserRegistrationService,
        FormBuilder,
    
        // providers used to create fake backend
        //  fakeBackendProvider,
        MockBackend,
        BaseRequestOptions],
    bootstrap: [AppComponent]
    })
    export class AppModule { }
    

    You didn't see any error because you use

    schemas: [CUSTOM_ELEMENTS_SCHEMA]
    

    You didn't provide your css but you will also need to import a material theme in your style.(s)css like:

    @import '~@angular/material/prebuilt-themes/deeppurple-amber.css';
    

    You can find a simple example here https://stackblitz.com/edit/angular-eszrpl

    0 讨论(0)
提交回复
热议问题