2016-02-11 100 views
4

我加入以下代碼位在我angular2應用程序來幫助周圍的應用程序移動時MDL重新註冊組件......Angular2與材料設計精簡版

ngAfterViewInit() { 
    componentHandler.upgradeDom(); 
} 

雖然它似乎是工作OK(如預期),我收到以下錯誤......

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

我還是很新的angular2和打字稿,但我想我需要進口的東西,所以我的代碼知道的ComponentHandler是什麼(即使它必須知道它是什麼,因爲它的工作原理,沒有此代碼不起作用???混淆ED)

+1

有人在看着這未來和有涉及路由組件的問題可能要看看[這個問題]( http://stackoverflow.com/questions/36162649/angular2-router-interacting-with-material-design-lite/36163652#36163652)。處理路由時有一些微妙之處。 –

回答

3

見它應該幫助你在你的代碼的頂部添加

declare var componentHandler: any; 

。請參閱上相應的handbook section在TypeScript中使用其他JavaScript庫

+0

我得到ReferenceError:componentHandler沒有定義..我不知道爲什麼..任何想法? – user2180794

2

如果您使用cli.angular工具來生成您的應用程序 這樣做,這樣就不需要到處複製代碼。

  1. 添加下面一行到typings.d.ts文件

    declare var componentHandler: any;
  2. 參考文件到您的組件文件,如下

    /// <reference path="../typings.d.ts" />