admin管理员组文章数量:1401776
I recently used the .config()
method on an angular module I was developing in order to use AngularJS's routes. It's looked something like:
myModule.config([
'$locationProvider',
'$routeProvider',
function ($locationProvider, $routeProvider) {
$locationProvider.html5Mode(false);
$locationProvider.hashPrefix('!');
$routeProvider.when('/', {
controller: 'myCtrl'
});
}]);
How does this method work? Can I configure my own services using this method? Should I?
I recently used the .config()
method on an angular module I was developing in order to use AngularJS's routes. It's looked something like:
myModule.config([
'$locationProvider',
'$routeProvider',
function ($locationProvider, $routeProvider) {
$locationProvider.html5Mode(false);
$locationProvider.hashPrefix('!');
$routeProvider.when('/', {
controller: 'myCtrl'
});
}]);
How does this method work? Can I configure my own services using this method? Should I?
Share Improve this question asked Oct 13, 2013 at 3:56 Kevin BealKevin Beal 10.9k13 gold badges72 silver badges93 bronze badges 2- 1 You can find some information on creating your own providers over at this Stack Overflow answer; the same article is available on the Angular.js wiki. – Michelle Tilley Commented Oct 13, 2013 at 4:05
- 1 Take a look at this answer. It'll probably answer your question aswell. – gustavohenke Commented Oct 13, 2013 at 4:05
1 Answer
Reset to default 4During the config
phase, only providers can be injected. So I think that you can create a custom provider and then configure it during the config
phase.
See this documentation (already mentioned by Brandon Tilley in a ment): https://github./angular/angular.js/wiki/Understanding-Dependency-Injection#configuring-providers
Basically angularjs first invoke the config method and then invoke the run method. During config only providers are available. A provider can then be used to create service instance.
本文标签: javascriptAngularJSHow can I use config() method with my own servicesStack Overflow
版权声明:本文标题:javascript - AngularJS - How can I use .config() method with my own services? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744290167a2599074.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论