Skip to content

Commit 2a64686

Browse files
authored
Merge pull request #1 from mdkitzman/master
Multiple query parameters with the same name
2 parents 0963f09 + 8a9a181 commit 2a64686

File tree

3 files changed

+22
-31
lines changed

3 files changed

+22
-31
lines changed

angular-url-parser.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,21 @@ angular
2121

2222
for( i = 0; i < queries.length; i++ ) {
2323
split = queries[i].split('=');
24-
searchObject[split[0]] = split[1];
24+
// handle query strings such as id=1&id=2&id=3
25+
if(searchObject.hasOwnProperty(split[0])) {
26+
var currentVal = searchObject[split[0]];
27+
var valueList;
28+
if(!angular.isArray(currentVal)){
29+
valueList = [];
30+
valueList.push(currentVal);
31+
} else {
32+
valueList = currentVal;
33+
}
34+
valueList.push(split[1]);
35+
searchObject[split[0]] = valueList;
36+
} else {
37+
searchObject[split[0]] = split[1];
38+
}
2539
}
2640

2741
return {

app/app.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ angular
99
ex3: 'http://localhost:3000/profile/yllieth',
1010
ex4: 'http://localhost:3000/profile/yllieth?page=1&sort=asc',
1111
ex5: 'http://localhost:3000#personal_information',
12+
ex6: 'http://localhost:3000/profile?id=1&id=2&sort=asc',
1213
current: location.href
1314
};
1415

@@ -27,4 +28,4 @@ angular
2728
};
2829

2930
this.changeUrl(this.selectedUrl);
30-
});
31+
});

app/index.html

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,11 @@ <h1>Angular Url Parser</h1>
2525
<div class="col-lg-6">
2626
<h2>Url examples</h2>
2727

28-
<div class="row" style="margin-top: 20px">
29-
<div class="col-lg-1"><input type="radio" ng-model="Demo.selectedUrl" ng-value="Demo.example.current" ng-change="Demo.changeUrl(Demo.example.current)"></div>
30-
<div class="col-lg-11"><strong>Current url : </strong><code><small>{{ Demo.example.current }}</small></code></div>
31-
</div>
32-
33-
<div class="row" style="margin-top: 20px">
34-
<div class="col-lg-1"><input type="radio" ng-model="Demo.selectedUrl" ng-value="Demo.example.ex1" ng-change="Demo.changeUrl(Demo.example.ex1)"></div>
35-
<div class="col-lg-11"><code><small>{{ Demo.example.ex1 }}</small></code></div>
36-
</div>
37-
38-
<div class="row" style="margin-top: 20px">
39-
<div class="col-lg-1"><input type="radio" ng-model="Demo.selectedUrl" ng-value="Demo.example.ex2" ng-change="Demo.changeUrl(Demo.example.ex2)"></div>
40-
<div class="col-lg-11"><code><small>{{ Demo.example.ex2 }}</small></code></div>
41-
</div>
42-
43-
<div class="row" style="margin-top: 20px">
44-
<div class="col-lg-1"><input type="radio" ng-model="Demo.selectedUrl" ng-value="Demo.example.ex3" ng-change="Demo.changeUrl(Demo.example.ex3)"></div>
45-
<div class="col-lg-11"><code><small>{{ Demo.example.ex3 }}</small></code></div>
46-
</div>
47-
48-
<div class="row" style="margin-top: 20px">
49-
<div class="col-lg-1"><input type="radio" ng-model="Demo.selectedUrl" ng-value="Demo.example.ex4" ng-change="Demo.changeUrl(Demo.example.ex4)"></div>
50-
<div class="col-lg-11"><code><small>{{ Demo.example.ex4 }}</small></code></div>
51-
</div>
52-
53-
<div class="row" style="margin-top: 20px">
54-
<div class="col-lg-1"><input type="radio" ng-model="Demo.selectedUrl" ng-value="Demo.example.ex5" ng-change="Demo.changeUrl(Demo.example.ex5)"></div>
55-
<div class="col-lg-11"><code><small>{{ Demo.example.ex5 }}</small></code></div>
28+
<div class="row" style="margin-top: 20px" ng-repeat="(demoName, url) in Demo.example" >
29+
<div class="col-lg-1"><input type="radio" ng-model="Demo.selectedUrl" ng-value="url" ng-change="Demo.changeUrl(url)"></div>
30+
<div class="col-lg-11"><strong>{{demoName}} : </strong><code><small>{{ url }}</small></code></div>
5631
</div>
32+
5733
</div>
5834

5935
<div class="col-lg-6">
@@ -126,4 +102,4 @@ <h2>API</h2>
126102
<script type="application/javascript" src="../angular-url-parser.js"></script>
127103
<script type="application/javascript" src="app.js"></script>
128104
</body>
129-
</html>
105+
</html>

0 commit comments

Comments
 (0)