@@ -11,37 +11,45 @@ Angular service to get simple methods to manipulate url parts
11
11
bower install yllieth/angular-url-parser --save
12
12
```
13
13
14
- Once the lib is downloaded,
14
+ Once the lib is downloaded, add a reference in your index.html
15
15
16
- 1 . add a reference in your index.html
16
+ ```
17
+ <script type="application/javascript" src="../bower_components/angular-url-parser/angular-url-parser.js"></script>
18
+ ```
17
19
18
- ` <script type="application/javascript" src="../bower_components/angular-url-parser/angular-url-parser.js"></script> `
19
-
20
- 2 . add the module in your angular application
21
-
22
- ``` javascript
23
- angular
24
- .module (' YOUR-ANGULAR-APP-NAME' , [
25
- ' ngUrlParser'
26
- ])
27
- .controller (' demoCtrl' , function (urlParser ) {
28
- this .parts = urlParser .parse ();
29
- this .protocol = urlParser .getProtocol ();
30
- this .host = urlParser .getHost ();
31
- this .hostname = urlParser .getHostname ();
32
- this .port = urlParser .getPort ();
33
- this .route = urlParser .getRoute ();
34
- this .routeAttributes = urlParser .getRouteAttributes ();
35
- this .queryString = urlParser .getQuerystring ();
36
- this .option = urlParser .getOption ();
37
- this .hash = urlParser .getHash ();
38
- })
39
- ```
20
+ ### Rails
40
21
41
- 3. enjoy!
22
+ In your ` Gemfile ` , add the following line:
23
+ ``` ruby
24
+ gem ' angular-url-parser-rails'
25
+ ```
26
+
27
+ In your ` application.js ` , add the following line:
28
+ ```
29
+ //= require angular-url-parser
30
+ ```
42
31
43
32
## Usage
44
33
34
+ ``` javascript
35
+ angular
36
+ .module (' YOUR-ANGULAR-APP-NAME' , [
37
+ ' ngUrlParser'
38
+ ])
39
+ .controller (' demoCtrl' , function (urlParser ) {
40
+ this .parts = urlParser .parse ();
41
+ this .protocol = urlParser .getProtocol ();
42
+ this .host = urlParser .getHost ();
43
+ this .hostname = urlParser .getHostname ();
44
+ this .port = urlParser .getPort ();
45
+ this .route = urlParser .getRoute ();
46
+ this .routeAttributes = urlParser .getRouteAttributes ();
47
+ this .queryString = urlParser .getQuerystring ();
48
+ this .option = urlParser .getOption ();
49
+ this .hash = urlParser .getHash ();
50
+ })
51
+ ```
52
+
45
53
- ` getProtocol([string] url): string ` : Return the protocol of the given url - Example: _ "http:"_ , _ "https:"_ , ...
46
54
- ` getHost([string] url): string ` : Return the host of the given url (without port) - Example: _ "github.com"_ , _ "localhost"_ , ...
47
55
- ` getHostname([string] url): string ` : Return the hostname of the given url (with port) - Example: _ "github.com"_ , _ "localhost:3000"_ , ...
@@ -57,13 +65,13 @@ Once the lib is downloaded,
57
65
58
66
{
59
67
"protocol" : " http:" ,
60
- " host" : " localhost:3000" ,
68
+ "host" : " localhost:3000" ,
61
69
"hostname" : " localhost" ,
62
- " port" : " 3000" ,
63
- " pathname" : " /models"
64
- " search" : " ?sort=asc" ,
70
+ "port" : " 3000" ,
71
+ "pathname" : " /models" ,
72
+ "search" : " ?sort=asc" ,
65
73
"searchObject" : { "sort" : " asc" },
66
- " hash" : " quantiles"
74
+ "hash" : " quantiles"
67
75
}
68
76
```
69
77
0 commit comments