我有一个我通过Angular CLI创建的角度2项目。我已按照Angular Material网站上的入门指南说明:https://material.angular.io/guide/getting-started。当我尝试使用md-side nav标签时,我仍然没有看到以Angular Material为主题的网站。
我的组件代码:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app works!';
}
这是我的组件html代码:
<md-sidenav-container>
<md-sidenav>
<!-- sidenav content -->
</md-sidenav>
<!-- primary content -->
</md-sidenav-container>
我的app.module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import {RouterModule} from '@angular/router';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {MdButtonModule, MdCheckboxModule} from '@angular/material';
import { AppComponent } from './app.component';
import { QuillEditorComponent } from './quill-editor/quill-editor.component';
import { LoginScreenComponent } from './login-screen/login-screen.component';
import { WelcomeScreenComponent } from './welcome-screen/welcome-screen.component';
import { PageNotFoundComponent } from './page-not-found/page-not-found.component';
import 'hammerjs';
@NgModule({
declarations: [
AppComponent,
QuillEditorComponent,
LoginScreenComponent,
WelcomeScreenComponent,
PageNotFoundComponent,
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
BrowserAnimationsModule,
MdButtonModule,
MdCheckboxModule,
RouterModule.forRoot([
{path: 'welcome', component: WelcomeScreenComponent},
{path: 'login', component: LoginScreenComponent},
{path: '', redirectTo: 'welcome', pathMatch: 'full'},
{path: '**', component: PageNotFoundComponent},
]),
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
我的package.json:
{
"name": "valu-app-poc",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^4.3.0",
"@angular/cdk": "^2.0.0-beta.8",
"@angular/common": "^4.3.0",
"@angular/compiler": "^4.3.0",
"@angular/compiler-cli": "^4.3.0",
"@angular/core": "^4.3.0",
"@angular/forms": "^4.3.0",
"@angular/http": "^4.3.0",
"@angular/material": "^2.0.0-beta.8",
"@angular/platform-browser": "^4.3.0",
"@angular/platform-browser-dynamic": "^4.3.0",
"@angular/platform-server": "^4.3.0",
"@angular/router": "^4.3.0",
"@types/quill": "0.0.31",
"core-js": "^2.4.1",
"hammerjs": "^2.0.8",
"quill": "^1.3.0",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"rxjs": "^5.1.0",
"typescript": "^2.4.1",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "1.0.4",
"@angular/compiler-cli": "^4.3.0",
"@types/jasmine": "2.5.38",
"@types/node": "^6.0.84",
"codelyzer": "~2.0.0",
"jasmine-core": "~2.5.2",
"jasmine-spec-reporter": "~3.2.0",
"karma": "~1.4.1",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^0.2.0",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.0",
"ts-node": "~2.0.0",
"tslint": "~4.5.0",
"typescript": "~2.2.0"
}
}
答案 0 :(得分:0)
更新环境
ng update @angular/cli @angular/core
然后将材料添加到您的项目中
ng add @angular/material
这将安装角钢/材料,并将进行使其工作所需的基本配置。