Search code examples
javascripttypescriptangularmaterial-design-lite

Angular2 with Material Design Lite


I have added the following bit of code in my angular2 app to help MDL re-register the components when moving around the app...

ngAfterViewInit() {
    componentHandler.upgradeDom();
}

And although it seems to be working ok (as expected) I am getting the following error...

(16,5): error TS2304: Cannot find name 'componentHandler'.

I'm still quite new to angular2 and typescript but I guess I need to import something so my code knows what componentHandler is(even though it must know what it is because it works and doesn't work without this code??? confused)


Solution

  • It should help you to add

    declare var componentHandler: any;
    

    at the top of your code. Please refer to the corresponding handbook section on Working with Other JavaScript Libraries in TypeScript.