0

I have an angular 2 project that I've created through Angular CLI. I have followed the instruction on the get started guide on the Angular Material website: https://material.angular.io/guide/getting-started. When I try to use the md-side nav tags, I still do not see the website themed with Angular Material.

My component code:

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app works!';


}

Here is my component html code:

<md-sidenav-container>
  <md-sidenav>
    <!-- sidenav content -->
  </md-sidenav>

  <!-- primary content -->
</md-sidenav-container>

My 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 { }

My 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"
  }
}
Nehal
  • 13,130
  • 4
  • 43
  • 59
Farhan Islam
  • 609
  • 2
  • 7
  • 21
  • You need to import the module to which md-sidenav belongs – Jota.Toledo Jul 18 '17 at 22:02
  • Possible duplicate of [How to import Angular Material in project?](https://stackoverflow.com/questions/45166844/how-to-import-angular-material-in-project) – Jota.Toledo Jul 18 '17 at 22:04
  • Are you getting any compiler/console error? Also, your sidenav had no content and most probably not open either. To see something add some content + add a button to open the sidenav – Nehal Jul 18 '17 at 23:24
  • @Jota.Toledo In other words, `import {MdSidenavModule} from '@angular/material` and placing it in `imports` array. – Edric Jul 19 '17 at 07:54
  • 1
    you also need to import a material theme into your app css, eg. @import "~@angular/material/prebuilt-themes/indigo-pink.css"; – glendaviesnz Jul 19 '17 at 07:54
  • Just tried the Material example, it works now. thanks for your help – Farhan Islam Jul 19 '17 at 18:59

1 Answers1

0

Update your environment

ng update @angular/cli @angular/core

Then add material to your project

ng add @angular/material

This will install angular/material and will also do basic configuration needed to make it work.

Vishal Hulawale
  • 472
  • 5
  • 9