webpack + angular material2模板解析器错误

时间:2017-03-21 11:38:28

标签: angular webpack angular-material

我尝试使用webpack打包项目。 但是当我添加角度材料2。控制台上会出现一些错误消息。 enter image description here

我使用材料的方式。

import { MaterialModule } from '@angular/material';
@NgModule({
    imports: [
        BrowserModule,
        FormsModule,
        LoginModule,
        AdminModule,
        AppRoutingModule,
        HttpModule,
        MaterialModule
    ],
    declarations: [
        AppComponent
    ],
    providers: [
        UserService,
        LoggerService,
        AuthGuardService
    ],
    bootstrap: [AppComponent]
})

组件文件:

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


@Component({
  selector: 'radio-ng-model-example',
  templateUrl: './angularMaterial.html',
  styleUrls: ['./angularMaterial.css'],
})
export class AngularMaterialComponent {
  favoriteSeason: string;

  seasons = [
    'Winter',
    'Spring',
    'Summer',
    'Autumn',
  ];
}

html文件:

<md-radio-group class="example-radio-group" [(ngModel)]="favoriteSeason">
    <md-radio-button class="example-radio-button" *ngFor="let season of seasons" [value]="season">
        {{season}}
    </md-radio-button>
</md-radio-group>
<div class="example-selected-value">Your favorite season is: {{favoriteSeason}}</div>

css文件:

.example-radio-group {
    display: inline-flex;
    flex-direction: column;
}

.example-radio-button {
    margin: 5px;
}

.example-selected-value {
    margin: 15px 0;
}

我使用angular material-radio demo

中的deom

1 个答案:

答案 0 :(得分:1)

导入材质模块时,您需要导入forRoot。例如,您需要将其声明为

imports: [
        BrowserModule,
        FormsModule,
        LoginModule,
        AdminModule,
        AppRoutingModule,
        HttpModule,
        MaterialModule.forRoot()
    ],