如何使用 Angular Material 2 创建自己的 Material 模块?

How can I create my own Material module using Angular Material 2?

我正在查看 angular/material2 and in the release note 的最新版本,他们说 Material 模块已被标记为已弃用。 这是发行说明中的​​话。

MaterialModule

MaterialModule (and MaterialRootModule) have been marked as deprecated. We've found that, with the current state of tree-shaking in the world, that using an aggregate NgModule like MaterialModule leads to tools not being able to eliminate code for components that aren't used.

In order to ensure that users end up with the smallest code size possible, we're deprecating MaterialModule, to be removed in the a subsequent release.

To replace MaterialModule, users can create their own "Material" module within their application (e.g., GmailMaterialModule) that imports only the set of components actually used in the application._

所以现在 MaterialModule 被弃用了,我想我不应该把它写在 NgModules 的 imports 数组中(如果我错了请纠正我)。那么我如何使用 <md-card>md-button 和其他组件。发行说明说 用户可以制作自己的 Material 模块 这是什么意思。

任何人都可以演示如何创建自己的 material 模块吗?

我在未来的 commits to master 他们更新文档的地方找到了答案。 https://github.com/angular/material2/compare/2.0.0-beta.3...master

第 3 步:导入组件模块

将 MaterialModule 作为导入添加到应用的根 NgModule 中。

为您要使用的每个组件导入 NgModule:

import {MdButtonModule, MdCheckboxModule} from '@angular/material';

@NgModule({
  imports: [MdButtonModule, MdCheckboxModule]
})

简而言之,您需要在 NgModel 中单独指定要使用的组件,而不是一个核心模块。这样做是为了在生成生产构建时从捆绑包中删除 redundant/unused 代码。