我开始使用Angular材料。在示例项目中,我安装了@ angular / cdk和@ angular / material,并在app.module上添加了引用。
然后在模板中我放了一个简单的对象:
<md-checkbox>Testing </md-checkbox>
但是当我运行应用程序时,复选框仅显示&#34;测试&#34;而不是复选框。控制台没有错误。
app.module:
import { environment } from '../environments/environment';
import { HomeComponent } from './home/home.component';
import { RouterModule } from '@angular/router';
import { ServiceHTTP } from './service-http.service';
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AngularFireModule} from 'angularfire2';
import { AngularFireDatabaseModule} from 'angularfire2/database';
import { AngularFireAuthModule} from 'angularfire2/auth';
import { AppComponent } from './app.component';
import { LoginComponent } from './login/login.component';
import { ConsultaComponent } from './consulta/consulta.component';
import { BsNavbarComponent } from './bs-navbar/bs-navbar.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MdButtonModule , MdCardModule , MdMenuModule , MdToolbarModule , MdIconModule , MdCheckbox} from '@angular/material';
import * as firebase from 'firebase';
@NgModule({
declarations: [
AppComponent,
LoginComponent,
ConsultaComponent,
HomeComponent,
BsNavbarComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
AngularFireModule.initializeApp(environment.firebase),
AngularFireDatabaseModule,
AngularFireAuthModule,
BrowserAnimationsModule,
MdButtonModule , MdCardModule , MdMenuModule , MdToolbarModule , MdIconModule,
RouterModule.forRoot([
{path: 'home', component: HomeComponent},
{path: 'login', component: LoginComponent},
{path: 'consulta', component : ConsultaComponent}
])
],
providers: [ServiceHTTP],
bootstrap: [AppComponent]
})
export class AppModule { }
有什么想法吗?
答案 0 :(得分:1)
问题是你只是导入了复选框,而不是整个模块(它使用了很多其他项目)。
import { ..., MdCheckboxModule } from '@angular/material';
应该解决问题!
(别忘了将它添加到@NgModule导入中)
答案 1 :(得分:0)
您还需要导入 MdCheckboxModule
imports: [
BrowserModule,
FormsModule,
HttpModule,
AngularFireModule.initializeApp(environment.firebase),
AngularFireDatabaseModule,
AngularFireAuthModule,
BrowserAnimationsModule,
MdButtonModule , MdCardModule , MdMenuModule , MdToolbarModule , MdCheckboxModule,MdIconModule,
RouterModule.forRoot([
{path: 'home', component: HomeComponent},
{path: 'login', component: LoginComponent},
{path: 'consulta', component : ConsultaComponent}
])
]