Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c283bf6

Browse files
committed
refactor($location): merged $locationConfig service into $locationProvider
1 parent b3c17f3 commit c283bf6

File tree

5 files changed

+38
-34
lines changed

5 files changed

+38
-34
lines changed

docs/content/guide/dev_guide.services.$location.ngdoc

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,26 +88,22 @@ setter methods that allow you to get or change the current URL in the browser.
8888

8989
## $location service configuration
9090

91-
To configure the `$location` service, you define the `$locationConfig` service which is an object
92-
with configuration properties:
91+
To configure the `$location` service, you get a hold of
92+
{@link angular.module.ng.$locationProvider $locationProvider} service and configure it with these
93+
methods:
9394

94-
- **html5Mode**: {boolean}<br />
95+
- **html5Mode(mode)**: {boolean}<br />
9596
`true` - see HTML5 mode<br />
9697
`false` - see Hashbang mode<br />
9798
default: `false`
9899

99-
- **hashPrefix**: {string}<br />
100+
- **hashPrefix(prefix)**: {string}<br />
100101
prefix used for Hashbang URLs (used in Hashbang mode or in legacy browser in Html5 mode)<br />
101102
default: `'!'`
102103

103104
### Example configuration
104105
<pre>
105-
angular.service('$locationConfig', function() {
106-
return {
107-
html5mode: true,
108-
hashPrefix: '!'
109-
};
110-
});
106+
$locationProvider.html5Mode(true).hashPrefix('!');
111107
</pre>
112108

113109
## Getter and setter methods

docs/src/templates/docs.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,6 @@ function TutorialInstructionsCtrl($cookieStore) {
152152
window.angular = window.angular || {};
153153
angular.module = angular.module || {};
154154

155-
angular.module.ngdocs = function($provide) {
156-
$provide.value('$locationConfig', {
157-
html5Mode: true,
158-
hashPrefix: '!'
159-
});
155+
angular.module.ngdocs = function($locationProvider) {
156+
$locationProvider.html5Mode(true).hashPrefix('!');
160157
};

src/Angular.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,6 @@ function ngModule($provide, $injector) {
954954
$provide.service('$filter', $FilterProvider);
955955
$provide.service('$formFactory', $FormFactoryProvider);
956956
$provide.service('$location', $LocationProvider);
957-
$provide.service('$locationConfig', $LocationConfigProvider);
958957
$provide.service('$log', $LogProvider);
959958
$provide.service('$parse', $ParseProvider);
960959
$provide.service('$resource', $ResourceProvider);

src/service/location.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -420,15 +420,35 @@ function locationGetterSetter(property, preprocess) {
420420
* For more information see {@link guide/dev_guide.services.$location Developer Guide: Angular Services: Using $location}
421421
*/
422422
function $LocationProvider(){
423-
this.$get = ['$rootScope', '$browser', '$sniffer', '$locationConfig', '$document',
424-
function( $rootScope, $browser, $sniffer, $locationConfig, $document) {
423+
var hashPrefix = '',
424+
html5Mode = false;
425+
426+
this.hashPrefix = function(prefix) {
427+
if (isDefined(prefix)) {
428+
hashPrefix = prefix;
429+
return this;
430+
} else {
431+
return html5Mode;
432+
}
433+
}
434+
435+
this.html5Mode = function(mode) {
436+
if (isDefined(mode)) {
437+
html5Mode = mode;
438+
return this;
439+
} else {
440+
return html5Mode;
441+
}
442+
};
443+
444+
this.$get = ['$rootScope', '$browser', '$sniffer', '$document',
445+
function( $rootScope, $browser, $sniffer, $document) {
425446
var currentUrl,
426447
basePath = $browser.baseHref() || '/',
427448
pathPrefix = pathPrefixFromBase(basePath),
428-
hashPrefix = $locationConfig.hashPrefix || '',
429449
initUrl = $browser.url();
430450

431-
if ($locationConfig.html5Mode) {
451+
if (html5Mode) {
432452
if ($sniffer.history) {
433453
currentUrl = new LocationUrl(convertToHtml5Url(initUrl, basePath, hashPrefix), pathPrefix);
434454
} else {
@@ -505,13 +525,3 @@ function $LocationProvider(){
505525
return currentUrl;
506526
}];
507527
}
508-
509-
//TODO(misko): refactor to service
510-
function $LocationConfigProvider(){
511-
this.$get = function() {
512-
return {
513-
html5Mode: false,
514-
hashPrefix: ''
515-
};
516-
};
517-
}

test/service/locationSpec.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,9 @@ describe('$location', function() {
308308

309309

310310
function initService(html5Mode, hashPrefix, supportHistory) {
311-
return function($provide){
312-
$provide.value('$locationConfig', {html5Mode: html5Mode, hashPrefix: hashPrefix});
311+
return function($provide, $locationProvider){
312+
$locationProvider.html5Mode(html5Mode);
313+
$locationProvider.hashPrefix(hashPrefix);
313314
$provide.value('$sniffer', {history: supportHistory});
314315
};
315316
}
@@ -576,7 +577,7 @@ describe('$location', function() {
576577
var root, link, originalBrowser, lastEventPreventDefault;
577578

578579
function configureService(linkHref, html5Mode, supportHist, attrs, content) {
579-
return function($provide){
580+
return function($provide, $locationProvider){
580581
var jqRoot = jqLite('<div></div>');
581582
attrs = attrs ? ' ' + attrs + ' ' : '';
582583
link = jqLite('<a href="' + linkHref + '"' + attrs + '>' + content + '</a>')[0];
@@ -586,7 +587,8 @@ describe('$location', function() {
586587

587588
$provide.value('$document', jqRoot);
588589
$provide.value('$sniffer', {history: supportHist});
589-
$provide.value('$locationConfig', {html5Mode: html5Mode, hashPrefix: '!'});
590+
$locationProvider.html5Mode(html5Mode);
591+
$locationProvider.hashPrefix('!');
590592
};
591593
}
592594

0 commit comments

Comments
 (0)