Jhipster / md-button is not a known element

2019-02-18 10:37发布

问题:

Hello I am using JHipster 4.0.1

I want integrate angular 2 material into my home.component.

I did : npm install material npm install angular2/{core,button}

 <html><head></head>
<body> 
<md-button>Hello </md-button></body></html>

the error is : md-button is not a known element

回答1:

For those using yarn rather than npm:

yarn add --exact @angular/material
yarn start

Import angular material module into src/main/webapp/app/shared/shared-libs.module.ts:

import { MaterialModule } from '@angular/material';

@NgModule({
    imports: [
        MaterialModule,
        ...        ],
    exports: [
        MaterialModule,
        ...

Add a theme into src/main/webapp/content/css/vendor.css:

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

Add some MD elements to src/main/webapp/app/home.component.html:

    <md-card>
        <button md-button class="mat-primary">Hello </button>
    </md-card>