"has no exported member" Error in my MTL module

时间:2016-04-25 09:07:05

标签: angular material-design-lite

:grinning: Anyone to help me with that ? I have a class MDL : MaterialDesignLiteUpgradeElements.ts

import {Directive, AfterViewInit} from 'angular2/core';
declare var componentHandler;
@Directive({
    selector: '[mdl]'
})
export class MDL implements AfterViewInit {
    ngAfterViewInit() {
        componentHandler.upgradeAllRegistered();
    }
}

And Following this stack post : Material Design Lite tooltips not working with Angular 2 I Added this :

 ngAfterViewInit() {
    componentHandler.upgradeDom();
  }

In the class managing the view using MTL But it say :

MaterialDesignLiteUpgradeElements has no exported member "componentHandler"

The console error :

EXCEPTION: TypeError: Cannot read property 'upgradeDom' of undefined

Any ideas ?

1 个答案:

答案 0 :(得分:2)

我没有进入Angular2但是,我在使用Material Design Lite(MDL)的ReactJS中遇到了同样的问题。

您收到EXCEPTION: TypeError: Cannot read property 'upgradeDom' of undefined错误的原因是MDL默认情况下不会导出任何模块。您可以按照以下建议导出模块。

  1. 您必须从componentHandler文件&手动导出material.js。组件文件中的import/require
  2. 或者,如果你使用像Webpack这样的捆绑器,你可以使用exports-loader&然后使用import/require导出componentHandler
  3. 我在这里给出了详细说明SO/Material Design Lite with ReactJS (import/require Issue)

    希望它有所帮助!