2016-03-24 56 views
1

我想重寫我現有的代碼,但我失敗了,我碰到這個錯誤:

ionic.bundle.js:8900 Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to: 
Error: [$injector:modulerr] Failed to instantiate module app.routes due to: 
Error: [$injector:unpr] Unknown provider: 

我的工作片段:

angular.module('app.routes', []) 
    .config(function() {}); 

我重寫代碼段(這個失敗):

(function() { 

    // use strict mode to write clean code! 
    'use strict'; 

    // This configures the routes 
    var RouteProvider = function() { 

    }; 

    // init the config 
    angular.module('app.routes', []) 
    .config(['', RouteProvider]); 

}()); 

我創建了一個Plunker此:Plunker

感謝您的幫助;)

回答

4

你有一個空字符串到您的通話.config - 這是有效地告訴角度要與一個空字符串作爲名字進入你的配置功能注入的服務。這不存在,所以你會得到一個未知的提供者錯誤 - 這是一個很不明顯的錯誤,因爲它試圖告訴你服務的名稱,但它是空白的,所以你最終只會得到Error: [$injector:unpr] Unknown provider:而沒有別的!

.config調用應該看起來更像是這樣的:

// init the config 
    angular.module('app.routes', []) 
    .config(RouteProvider); 

你不需要數組語法,如果你沒有真正注入到任何功能。

+0

我會將我的評論添加爲答案... –

相關問題