我在我的角度應用程序中使用角度路由段,並嘗試從json提要配置段。
我有這個問題,因爲我不知道如何注入$http
到app.config
函數。這種失敗Unknown provider: $http
myApp.config(["$http", "$routeSegmentProvider", function ($http, $routeSegmentProvider) {
/* setup navigation here calling $routeSegmentProvider.when a number of times */
}
因此,而不是注入$ HTTP到config
,我也試過注射$routeSegmentProvider
爲myApp.run
myApp.run(["$http", "$routeSegment", function($http, $routeSegment) {
/* can use $http here to get data, but $routeSegment is not the same here */
/* $routeSegment does not have the when setup method */
}]);
我也試過
myApp.run(["$http", "$routeSegmentProvider", function($http, $routeSegmentProvider)
,但我得到Unknown provider: $routeSegmentProviderProvider <- $routeSegmentProvider
你可以在這裏找到你的答案:http://stackoverflow.com/questions/15937267/inject-service-in-app-config – 2014-09-03 12:17:17
@DavidBohunek我想我以前遇到過這個例子,但我無法讓它工作出於某種原因。我決定現在與cliff.meyers一起回答。 – gwin003 2014-09-03 12:41:45