Angular4 webpack2 @angular/material 构建错误

Angular4 webpack2 @angular/material build error

我的开发可以成功,但是构建时出错,我该怎么办

未处理的承诺拒绝:模板解析错误: 无法绑定到 'mdmenutriggerfor',因为它不是 'a' 的已知 属性。 ("Home Blog About ][mdmenutriggerfor]=theme>Theme Blue Ocean ][mdmenutriggerfor]=account>TaylorPzreal ; Task: Promise.then ; Value: Error: 模板解析错误: 无法绑定到 'mdmenutriggerfor',因为它不是 'a' 的已知 属性。 ("首页博客关于][mdmenutriggerfor]=theme>主题蓝海][mdmenutriggerfor]=account>TaylorPzreal http://localhost:3000/dist/vendor.b3014186753d08da08d0.js:2:451794)[] 在 TemplateParser.parse (http://localhost:3000/dist/vendor.b3014186753d08da08d0.js:2:632968) [] 在 JitCompiler._compileTemplate (http://localhost:3000/dist/vendor.b3014186753d08da08d0.js:2:819358) [] 在 [] 错误:模板解析错误:

使用下面列表中的选择器代替 mdmenutriggerfor:

selector: `[md-menu-trigger-for], [mat-menu-trigger-for],
         [mdMenuTriggerFor], [matMenuTriggerFor]`,

<button md-icon-button [mdMenuTriggerFor]="menu"> <md-icon>more_vert</md-icon> </button>

注意:[md-menu-trigger-for], [mat-menu-trigger-for] 已弃用。

来源:https://github.com/angular/material2/blob/94320c4e68a8e6a2093b704157900cd6cd8388e2/src/lib/menu/menu-trigger.ts#L37-L38

我用两种方法解决了:

  1. 将'html-loader'替换为'raw-loader';

  2. 注释掉最小化行。

    new webpack.LoaderOptionsPlugin({
     htmlLoader: {
      minimize: DEVELOPMENT // workaround for ng2
     },
     // minimize: PRODUCTION, // Comment out this line
     debug: DEVELOPMENT,
     options: {
      context: __dirname
     }
    }),