@@ -22,7 +22,10 @@ const DEFAULT_PORTS: {[key: string]: number} = {
22
22
} ;
23
23
24
24
/**
25
- * Docs TBD.
25
+ * Location service that provides a drop-in replacement for the $location service
26
+ * provided in AngularJS.
27
+ *
28
+ * @see [Using the Angular Unified Location Service](guide/upgrade#using-the-unified-angular-location-service)
26
29
*
27
30
* @publicApi
28
31
*/
@@ -321,12 +324,17 @@ export class $locationShim {
321
324
}
322
325
323
326
/**
324
- * Register URL change listeners. This API can be used to catch updates performed by the
325
- * AngularJS framework. These changes are a subset of the `$locationChangeStart/Success` events
326
- * as those events fire when AngularJS updates it's internally referenced version of the browser
327
- * URL. It's possible for `$locationChange` events to happen, but for the browser URL
327
+ * Registers listeners for URL changes. This API is used to catch updates performed by the
328
+ * AngularJS framework. These changes are a subset of the `$locationChangeStart` and
329
+ * `$locationChangeSuccess` events which fire when AngularJS updates its internally-referenced
330
+ * version of the browser URL.
331
+ *
332
+ * It's possible for `$locationChange` events to happen, but for the browser URL
328
333
* (window.location) to remain unchanged. This `onChange` callback will fire only when AngularJS
329
334
* actually updates the browser URL (window.location).
335
+ *
336
+ * @param fn The callback function that is triggered for the listener when the URL changes.
337
+ * @param err The callback function that is triggered when an error occurs.
330
338
*/
331
339
onChange (
332
340
fn : ( url : string , state : unknown , oldUrl : string , oldState : unknown ) => void ,
@@ -346,6 +354,11 @@ export class $locationShim {
346
354
} ) ;
347
355
}
348
356
357
+ /**
358
+ * Parses the provided URL, and sets the current URL to the parsed result.
359
+ *
360
+ * @param url The URL string.
361
+ */
349
362
$$parse ( url : string ) {
350
363
let pathUrl : string | undefined ;
351
364
if ( url . startsWith ( '/' ) ) {
@@ -366,6 +379,12 @@ export class $locationShim {
366
379
this . composeUrls ( ) ;
367
380
}
368
381
382
+ /**
383
+ * Parses the provided URL and its relative URL.
384
+ *
385
+ * @param url The full URL string.
386
+ * @param relHref A URL string relative to the full URL string.
387
+ */
369
388
$$parseLinkUrl ( url : string , relHref ?: string | null ) : boolean {
370
389
// When relHref is passed, it should be a hash and is handled separately
371
390
if ( relHref && relHref [ 0 ] === '#' ) {
@@ -413,9 +432,8 @@ export class $locationShim {
413
432
}
414
433
415
434
/**
416
- * This method is getter only.
417
- *
418
- * Return full URL representation with all segments encoded according to rules specified in
435
+ * Retrieves the full URL representation with all segments encoded according to
436
+ * rules specified in
419
437
* [RFC 3986](http://www.ietf.org/rfc/rfc3986.txt).
420
438
*
421
439
*
@@ -428,12 +446,8 @@ export class $locationShim {
428
446
absUrl ( ) : string { return this . $$absUrl ; }
429
447
430
448
/**
431
- * This method is getter / setter.
432
- *
433
- * Return URL (e.g. `/path?a=b#hash`) when called without any parameter.
434
- *
435
- * Change path, search and hash, when called with parameter and return `$location`.
436
- *
449
+ * Retrieves the current URL, or sets a new URL. When setting a URL,
450
+ * changes the path, search, and hash, and returns a reference to its own instance.
437
451
*
438
452
* ```js
439
453
* // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
@@ -463,10 +477,7 @@ export class $locationShim {
463
477
}
464
478
465
479
/**
466
- * This method is getter only.
467
- *
468
- * Return protocol of current URL.
469
- *
480
+ * Retrieves the protocol of the current URL.
470
481
*
471
482
* ```js
472
483
* // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
@@ -477,11 +488,9 @@ export class $locationShim {
477
488
protocol ( ) : string { return this . $$protocol ; }
478
489
479
490
/**
480
- * This method is getter only .
491
+ * Retrieves the protocol of the current URL .
481
492
*
482
- * Return host of current URL.
483
- *
484
- * Note: compared to the non-AngularJS version `location.host` which returns `hostname:port`, this
493
+ * In contrast to the non-AngularJS version `location.host` which returns `hostname:port`, this
485
494
* returns the `hostname` portion only.
486
495
*
487
496
*
@@ -500,10 +509,7 @@ export class $locationShim {
500
509
host ( ) : string { return this . $$host ; }
501
510
502
511
/**
503
- * This method is getter only.
504
- *
505
- * Return port of current URL.
506
- *
512
+ * Retrieves the port of the current URL.
507
513
*
508
514
* ```js
509
515
* // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
@@ -514,16 +520,12 @@ export class $locationShim {
514
520
port ( ) : number | null { return this . $$port ; }
515
521
516
522
/**
517
- * This method is getter / setter.
518
- *
519
- * Return path of current URL when called without any parameter.
523
+ * Retrieves the path of the current URL, or changes the path and returns a reference to its own
524
+ * instance.
520
525
*
521
- * Change path when called with parameter and return `$location`.
522
- *
523
- * Note: Path should always begin with forward slash (/), this method will add the forward slash
526
+ * Paths should always begin with forward slash (/). This method adds the forward slash
524
527
* if it is missing.
525
528
*
526
- *
527
529
* ```js
528
530
* // given URL http://example.com/#/some/path?foo=bar&baz=xoxo
529
531
* let path = $location.path();
@@ -548,11 +550,8 @@ export class $locationShim {
548
550
}
549
551
550
552
/**
551
- * This method is getter / setter.
552
- *
553
- * Return search part (as object) of current URL when called without any parameter.
554
- *
555
- * Change search part when called with parameter and return `$location`.
553
+ * Retrieves a map of the search parameters of the current URL, or changes a search
554
+ * part and returns a reference to its own instance.
556
555
*
557
556
*
558
557
* ```js
@@ -585,8 +584,7 @@ export class $locationShim {
585
584
* If `paramValue` is `true`, the property specified via the first argument will be added with no
586
585
* value nor trailing equal sign.
587
586
*
588
- * @return {Object } If called with no arguments returns the parsed `search` object. If called with
589
- * one or more arguments returns `$location` object itself.
587
+ * @return {Object } The parsed `search` object of the current URL, or the changed `search` object.
590
588
*/
591
589
search ( ) : { [ key : string ] : unknown } ;
592
590
search ( search : string | number | { [ key : string ] : unknown } ) : this;
@@ -633,12 +631,8 @@ export class $locationShim {
633
631
}
634
632
635
633
/**
636
- * This method is getter / setter.
637
- *
638
- * Returns the hash fragment when called without any parameters.
639
- *
640
- * Changes the hash fragment when called with a parameter and returns `$location`.
641
- *
634
+ * Retrieves the current hash fragment, or changes the hash fragment and returns a reference to
635
+ * its own instance.
642
636
*
643
637
* ```js
644
638
* // given URL http://example.com/#/some/path?foo=bar&baz=xoxo#hashValue
@@ -660,7 +654,7 @@ export class $locationShim {
660
654
}
661
655
662
656
/**
663
- * If called, all changes to $location during the current `$digest` will replace the current
657
+ * Changes to ` $location` during the current `$digest` will replace the current
664
658
* history record, instead of adding a new one.
665
659
*/
666
660
replace ( ) : this {
@@ -669,15 +663,13 @@ export class $locationShim {
669
663
}
670
664
671
665
/**
672
- * This method is getter / setter.
673
- *
674
- * Return the history state object when called without any parameter.
666
+ * Retrieves the history state object when called without any parameter.
675
667
*
676
668
* Change the history state object when called with one parameter and return `$location`.
677
669
* The state object is later passed to `pushState` or `replaceState`.
678
670
*
679
- * NOTE: This method is supported only in HTML5 mode and only in browsers supporting
680
- * the HTML5 History API (i.e. methods `pushState` and `replaceState`) . If you need to support
671
+ * This method is supported only in HTML5 mode and only in browsers supporting
672
+ * the HTML5 History API methods such as `pushState` and `replaceState`. If you need to support
681
673
* older browsers (like IE9 or Android < 4.0), don't use this method.
682
674
*
683
675
*/
@@ -694,7 +686,8 @@ export class $locationShim {
694
686
}
695
687
696
688
/**
697
- * Docs TBD.
689
+ * The factory function used to create an instance of the `$locationShim` in Angular,
690
+ * and provides an API-compatiable `$locationProvider` for AngularJS.
698
691
*
699
692
* @publicApi
700
693
*/
@@ -704,6 +697,9 @@ export class $locationShimProvider {
704
697
private platformLocation : PlatformLocation , private urlCodec : UrlCodec ,
705
698
private locationStrategy : LocationStrategy ) { }
706
699
700
+ /**
701
+ * Factory method that returns an instance of the $locationShim
702
+ */
707
703
$get ( ) {
708
704
return new $locationShim (
709
705
this . ngUpgrade . $injector , this . location , this . platformLocation , this . urlCodec ,
0 commit comments