- UID
- 396408
- 热情
- 2360
- 人气
- 3194
- 主题
- 24
- 帖子
- 1157
- 精华
- 0
- 积分
- 3382
- 分享
- 0
- 记录
- 0
- 相册
- 2
- 好友
- 1
- 日志
- 0
- 在线时间
- 1438 小时
- 注册时间
- 2015-2-22
- 阅读权限
- 30
- 最后登录
- 2025-7-1
  
升级   92.13% - UID
- 396408
- 热情
- 2360
- 人气
- 3194
- 主题
- 24
- 帖子
- 1157
- 精华
- 0
- 积分
- 3382
- 阅读权限
- 30
- 注册时间
- 2015-2-22
|
本帖最后由 liuruihua 于 2015-9-3 19:12 编辑
reference: http://stackoverflow.com/questio ... m-the-url-parameter
url test1.html?albumId=5
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Angular test</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
</head>
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
<ul>
<li ng-repeat="photo in photos | myFilter | orderBy:id">
<a href="#" ng-click="toggle($index)">{{photo.title}}</a>
<a href="{{photo.url}}" class="thumb">
<img ng-src="{{photo.thumbnailUrl}}" ng-show="selected == $index"/>
</a>
</li>
</ul>
</div>
<script>
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,
function(m,key,value) {
vars[key] = value;
});
return vars;
}
var app = angular.module('myApp', []);
app.filter('myFilter', function() {
return function(items) {
if (typeof items == 'undefined') {
return items;
}
var albumId = parseInt(getUrlVars()["albumId"]);
alert(albumId);
var filtered = [];
for (var i = 0; i < items.length; i++) {
var item = items;
if (item.albumId === albumId) {
filtered.push(item);
}
}
return filtered;
};
});
app.controller('customersCtrl', function($scope, $http) {
$scope.selected = -1;
$http.get("http://jsonplaceholder.typicode.com/photos")
.success(function (response) {
$scope.photos = response;
$scope.toggle = function ($index) {
$scope.selected = $index;
}
});
});
</script>
</body>
</html>
|
|