路由切换及播放

来源:互联网 发布:2017苹果10月份mac 编辑:程序博客网 时间:2024/06/04 00:40
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="libs/angular.min.js"></script>
<script src="libs/angular-route.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
angular.module("app",["ngRoute"]).config(function($routeProvider){
     $routeProvider.when("/:type",{
          templateUrl:"table.html",
          controller:"mc"
     }).otherwise({
      redirectTo:"/经典老歌"
  });

})
.controller("mc", function($scope, $routeParams,$filter,$http) {
var type = $routeParams.type;//分类
$http.get('sings.json').success(function(data) {
//获取json中的数据
$scope.datas = data;
//创建数组过滤器
var $f=$filter("filter");
//过滤数据,根据选择的类别,进行对应显示
$scope.sings=$f(data,{type:type});

}).error(function() {
alert("an unexpected error ocurred!");
});


})


</script>

</head>
<body ng-app="app">
<nav>
<a href="#/经典老歌">经典老歌</a>
<a href="#/好听">好听</a>
</nav>


<div style="width: 300px; height: 200px; background: yellow;" ng-view>


</div>
</body>

</html>

table.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
tr td{
border-bottom: 1px solid;
margin: 1px;
}
</style>
</head>
<body>
<table>
<thead>
</thead>
<tr>
<td><input type="checkbox"/></td>
<td>全选</td>
<td colspan="2"><input type="button" value="播放选中的歌曲" /></td>
<td>播放</td>
<td>歌词</td>
<td>下载</td>
</tr>
<tr ng-repeat="s in sings" >
<td><input type="checkbox"/></td>
<td> {{$index+1 }}</td>
<td>{{s.sname}}</td>
<td>{{s.author}}</td>
<td><a href="{{s.spath}}">播放</a></td>
<td>歌词</td>
<td>下载</td>
</tr>
</table>
</body>
</html>

json

[{"sname":"富士山下","author":"陈奕迅","spath":"music/fssx.mp3","type":"经典老歌"},
{"sname":"刚刚好","author":"薛之谦","spath":"music/ggh.mp3","type":"经典老歌"},
{"sname":"后会无期","author":"徐良","spath":"music/hhwq.mp3","type":"好听"},
{"sname":"犯贱","author":"徐良","spath":"music/fj.mp3","type":"好听"}
]


原创粉丝点击