2016-11-22 68 views
10

我正試圖用JiT和angular-cli學習這個tutorial。我在瀏覽器控制檯中發現了以下錯誤,但在終端運行/構建應用程序時沒有錯誤。錯誤「System is not defined(...)」INTERNATIONALIZATION(I18N),angular-cli

未捕獲的ReferenceError:系統沒有定義(...)

未捕獲的錯誤:無法找到模塊」 ./locale/messages.fr.xlf!text'.(...)

enter image description here

我在github中的代碼https://github.com/sayedrakib/internationalization_project.git

根據教程中的說明,我在根文件夾中添加了systemjs-text-plugin.js。 文件結構 enter image description here

我想我已經搞砸了,在某些文件的文件路徑,因爲我在教程和角CLI創建的文件結構感受到假定文件結構是不一樣的。

+0

同樣在這裏:'系統未定義' – Mick

+0

將此作爲問題添加到https://github.com/angular/angular.io/issues/3238上的angular.io文檔部分。 – MeMeMax

回答

1

花了我一些時間來弄清楚這一點!在根目錄(/應用)

  1. 下載system.js,但它和腳本標記之前導入它:

    如果你按照文件,改變這種狀況。

  2. index.html中刪除System.import( '應用')
  3. 從系統重命名一切SystemJS(index.html的,國際化功能,provides.ts)

最後它看起來像這樣:

的index.html

<body> 
    <app-root>Loading...</app-root> 

    <script src="system.js"></script> 
    <script> 
    // Get the locale id somehow 
    document.locale = 'es'; 

    // Map to the text plugin 
    SystemJS.config({ 
     map: { 
     text: 'systemjs-text-plugin.js' 
     } 
    }); 
    </script> 
</body> 

I18N-providers.ts

export function getTranslationProviders(): Promise<Object[]> { 
    [...] 
} 

declare let SystemJS: any; 

function getTranslationsWithSystemJs(file: string) { 
    return SystemJS.import(file + '!text'); // relies on text plugin 
} 

我打開GitHub Issue來更新文檔。

+0

但是,在你的應用中包含依賴關係是不好的做法,因爲你不想讓它們在GIT中,是不是?因此這不是一個好的解決方案。 – MeMeMax

+0

你當然可以通過npm添加它。我猜這個文檔的問題是systemjs是angular-cli的一部分,而不是angular-cli的一部分。 – Mick

+0

好的。我試圖使用這種解決方法,但文本文件無法加載。錯誤:GET http:// localhost:4200/text 404(Not Found)。你做到了嗎? – MeMeMax

2

我可以看到你正在使用angular-cli,比如果你想加載3party libery,你需要使用angular-cli.json文件。

首先運行在您的應用程序目錄npm install systemjs 其次,您需要在angular-cli.json文件中添加systemjs的路徑。

"scripts": [ 
    "../node_modules/systemjs/dist/system.js" 
    ] 

如果你需要加載其他3party libery只需重複2個階段。

+0

這不會按照Angular的指示工作,您應該在您的index.html中包含

  • 11. 「Shadowbox is not defined」錯誤,暗示Shadowbox.init(shadowbox_conf)?
  • 12. Vuejs - require is not defined
  • 13. 「Uncaught RefereceError:txtfile is not defined」
  • 14. Uncaught ReferenceError:define is not defined
  • 15. Uncaught ReferenceError:text is not defined
  • 16. error'_'is not defined no-undef
  • 17. Sitecore「Uncaught ReferenceError:MultilistWithSearch is not defined」
  • 18. React + Material UI,require is not defined
  • 19. Javascript:「[classname] is not defined」error
  • 20. yeoman mongodb - require is not defined
  • 21. 「moment is not defined」使用moment.js
  • 22. ReactJS with Webpack:Uncaught ReferenceError:require is not defined
  • 23. jquery placeholder plugin'jQuery is not defined'
  • 24. Backbone.Marionette - Grunt Browserify - 「require is not defined」
  • 25. Uncaught referenceError:$ counter is not defined
  • 26. ObjectionJS relationship modelClass is not defined
  • 27. xo lint error:`document` is not defined
  • 28. DataTables FixedColumn「Uncaught ReferenceError:FixedColumns is not defined」
  • 29. Gulp Browserify ReferenceError:source is not defined
  • 30. Laravel生成一個錯誤「Echo is Echo is not defined」