angular cli 中 angular material 2 的问题

Issue with angular material 2 in angular cli

我正在尝试将 angular material2 添加到我的项目中。 (我使用 angular-cli) 但是,当我 运行 ng serve:

时出现以下错误

material.es5.js:177 Could not find Angular Material core theme. Most Material components may not work as expected. For more info refer to the theming guide: https://material.angular.io/guide/theming

尽管我将它添加到我的全局样式文件中。

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

我该如何解决?谢谢。

在您的 angular-cli.json 下:

"apps": [

  //....

"styles": [

   //... , 

  "../node_modules/@angular/material/prebuilt-themes/indigo-pink.css" //<--add this
  ],
]