我想在AngularJS 1.x的應用程序使用打字稿性質「模塊」。AngularJS +打字稿:遺漏的類型錯誤:無法讀取的不確定
我的應用程序已經使用Webpack作爲模塊加載程序,因此我將其配置爲處理TypeScript編譯(將所有* .js源文件重命名爲* .ts後),並設法使其工作。所以它編譯沒有錯誤,並生成我的JavaScript輸出文件。
唯一的問題是,當我運行在瀏覽器上的應用程序,它不工作,我得到這個控制檯錯誤:
Uncaught TypeError: Cannot read property 'module' of undefined
還有:
Uncaught Error: [$injector:modulerr] Failed to instantiate module myModuleName due to: Error: [$injector:nomod] Module 'myModuleName' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
我的猜測是由於某種原因angular
對象爲空,它在我嘗試訪問angular.module
時抱怨。
我不明白爲什麼它是如此,因爲當我在它成功地編譯代碼使用import angular from 'angular/angular';
。
完整的源代碼可here。
的WebPack輸出:
Hash: 824157db8ed6acf47fc1 Version: webpack 2.2.1 Time: 2242ms Asset Size Chunks Chunk Names othello-bundle.js 1.27 MB 0 [emitted] [big] app othello-bundle.js.map 1.51 MB 0 [emitted] app [0] ./~/angular/angular.js 1.24 MB {0} [built] [5] ./app/services/othello_AI.ts 8.65 kB {0} [built] [6] ./app/services/othello_handler.ts 9.3 kB {0} [built] [7] ./app/index.ts 723 bytes {0} [built] + 4 hidden modules
你是什麼角度版本?我沒有看到的package.json或bower.json角 – DMCISSOKHO
是1.6,你可以從我的package.json看到:https://github.com/ShinDarth/Othello/blob/typescript/package.json#L9 – ShinDarth
我的不好,你是否在加載時檢查了你的腳本命令,或者如果你同時加載angular和angular.min? – DMCISSOKHO