Skip to content

Commit 3be6835

Browse files
shweibtford
authored andcommitted
docs($location): add examples for some methods
Closes angular#9754
1 parent a3d7977 commit 3be6835

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

src/ng/location.js

+50-2
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,13 @@ var locationPrototype = {
327327
* Return full url representation with all segments encoded according to rules specified in
328328
* [RFC 3986](http://www.ietf.org/rfc/rfc3986.txt).
329329
*
330+
*
331+
* ```js
332+
* // given url http://example.com/#/some/path?foo=bar&baz=xoxo
333+
* var absUrl = $location.absUrl();
334+
* // => "http://example.com/#/some/path?foo=bar&baz=xoxo"
335+
* ```
336+
*
330337
* @return {string} full url
331338
*/
332339
absUrl: locationGetter('$$absUrl'),
@@ -342,6 +349,13 @@ var locationPrototype = {
342349
*
343350
* Change path, search and hash, when called with parameter and return `$location`.
344351
*
352+
*
353+
* ```js
354+
* // given url http://example.com/#/some/path?foo=bar&baz=xoxo
355+
* var url = $location.url();
356+
* // => "/some/path?foo=bar&baz=xoxo"
357+
* ```
358+
*
345359
* @param {string=} url New url without base prefix (e.g. `/path?a=b#hash`)
346360
* @return {string} url
347361
*/
@@ -366,6 +380,13 @@ var locationPrototype = {
366380
*
367381
* Return protocol of current url.
368382
*
383+
*
384+
* ```js
385+
* // given url http://example.com/#/some/path?foo=bar&baz=xoxo
386+
* var protocol = $location.protocol();
387+
* // => "http"
388+
* ```
389+
*
369390
* @return {string} protocol of current url
370391
*/
371392
protocol: locationGetter('$$protocol'),
@@ -379,6 +400,13 @@ var locationPrototype = {
379400
*
380401
* Return host of current url.
381402
*
403+
*
404+
* ```js
405+
* // given url http://example.com/#/some/path?foo=bar&baz=xoxo
406+
* var host = $location.host();
407+
* // => "example.com"
408+
* ```
409+
*
382410
* @return {string} host of current url.
383411
*/
384412
host: locationGetter('$$host'),
@@ -392,6 +420,13 @@ var locationPrototype = {
392420
*
393421
* Return port of current url.
394422
*
423+
*
424+
* ```js
425+
* // given url http://example.com/#/some/path?foo=bar&baz=xoxo
426+
* var port = $location.port();
427+
* // => 80
428+
* ```
429+
*
395430
* @return {Number} port
396431
*/
397432
port: locationGetter('$$port'),
@@ -410,6 +445,13 @@ var locationPrototype = {
410445
* Note: Path should always begin with forward slash (/), this method will add the forward slash
411446
* if it is missing.
412447
*
448+
*
449+
* ```js
450+
* // given url http://example.com/#/some/path?foo=bar&baz=xoxo
451+
* var path = $location.path();
452+
* // => "/some/path"
453+
* ```
454+
*
413455
* @param {(string|number)=} path New path
414456
* @return {string} path
415457
*/
@@ -435,10 +477,9 @@ var locationPrototype = {
435477
* var searchObject = $location.search();
436478
* // => {foo: 'bar', baz: 'xoxo'}
437479
*
438-
*
439480
* // set foo to 'yipee'
440481
* $location.search('foo', 'yipee');
441-
* // => $location
482+
* // $location.search() => {foo: 'yipee', baz: 'xoxo'}
442483
* ```
443484
*
444485
* @param {string|Object.<string>|Object.<Array.<string>>} search New search params - string or
@@ -508,6 +549,13 @@ var locationPrototype = {
508549
*
509550
* Change hash fragment when called with parameter and return `$location`.
510551
*
552+
*
553+
* ```js
554+
* // given url http://example.com/some/path?foo=bar&baz=xoxo#hashValue
555+
* var hash = $location.hash();
556+
* // => "hashValue"
557+
* ```
558+
*
511559
* @param {(string|number)=} hash New hash fragment
512560
* @return {string} hash
513561
*/

0 commit comments

Comments
 (0)