2016-11-16 35 views
0

去關Angular2教程,爲了使在內存中後臺的正常工作,有必須在系統config.ts包設置如下:如何修改Angular-cli的配置以允許內存後端?

packages: { 
'app': { main: './main.js', defaultExtension: 'js' }, 
'api' : { defaultExtension : 'js' }, 
'rxjs': { defaultExtension: 'js' }, 
} 

我已經把一個Angular2應用,我正在使用Angular-api捆綁生產。但是,Angular-api使用webpack,它似乎沒有可比較的配置文件來設置默認擴展。我的應用程序可以建立並沒有錯誤送達,但加載頁面我的數據時抓住服務是無功能的,我得到了以下錯誤:

error_handler.js:47EXCEPTION: unable to parse url './projects'; original error: Cannot read property 'split' of undefined

有埋內的一些角度,CLI配置文件node_modules文件夾,但似乎沒有包含軟件包或默認擴展名。我會非常感激任何幫助。

+0

如果您使用的是CLI生產和開發它是不是我不明白?如果你正在使用angular-cli,這是一個簡單的解決方案。 –

+0

意圖是使用CLI進行生產。它似乎正在縮小和正確捆綁一切,我只有在內存後端數據服務的問題。 – calebjmatthews

+0

你有沒有在package.json中安裝軟件包?你應該在「依賴關係」下面看到一行:「angular-in-memory-web-api」:「^ 0.1.15」。 –

回答

0

CLI已知與內存中的角度web-api不兼容,或者更具體地說,它如何使用core-js。如果你通過你的日誌在控制檯上,你會看到這樣的錯誤:

Cannot find type definition file for 'core-js'. 

爲了解決這個問題,這樣做:

  1. 安裝核心-JS打字:NPM安裝--save @ types/core-js
  2. 編輯tsconfig.json並將「lib」值設置爲「es5」。它應該是這樣的:

{ "compilerOptions": { "declaration": false, "emitDecoratorMetadata": true, "experimentalDecorators": true, "lib": ["es5", "dom"], "mapRoot": "./", "module": "es6", "moduleResolution": "node", "outDir": "../dist/out-tsc", "sourceMap": true, "target": "es5", "typeRoots": [ "../node_modules/@types" ] } }

相關問題