![](/img/trans.png)
[英]How can I organize angularjs factories/services/config/controllers files in different locations?
[英]AngularJS - How can I use .config() method with my own services?
我最近在我正在開發的角度模塊上使用了.config()
方法,以便使用AngularJS的路由。 看起來像是這樣的:
myModule.config([
'$locationProvider',
'$routeProvider',
function ($locationProvider, $routeProvider) {
$locationProvider.html5Mode(false);
$locationProvider.hashPrefix('!');
$routeProvider.when('/', {
controller: 'myCtrl'
});
}]);
這種方法有什么用? 我可以使用此方法配置自己的服務嗎? 我是不是該?
在config
階段,只能注入提供程序。 所以我認為你可以創建一個自定義提供程序,然后在config
階段配置它。
請參閱此文檔(Brandon Tilley在評論中已經提到過): https : //github.com/angular/angular.js/wiki/Understanding-Dependency-Injection#configuring-providers
基本上angularjs首先調用config方法,然后調用run方法。 在配置期間,只有提供商可用。 然后可以使用提供程序來創建服務實例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.