基本介绍

1、引入的route模块可以对路由的变化做出响应

2、创建的控制器中依然需要$http向后台请求数据

3、php中二维数据的遍历用的是foreach

4、php中$arr=array(),$arr[] 可以被自动补充所缺失的索引

5、在ng-repeat中,如果数据相同的话会报错(ngRepeat:dupes),解决办法是后面添加track by $index===》list in lists track by $index

基本使用

html

<!DOCTYPE html>
<html lang="en" ng-app="Music">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body,ol,li{
margin: 0;
padding: 0;
}
.wrap{
width: 400px;
margin: 50px auto;
}
nav{
display: flex;
height: 40px;
border: 1px solid #000;
}
nav a{
flex: 1;
height: 40px;
text-decoration: none;
color: #000;
text-align: center;
line-height: 40px;
position: relative;
}
nav a:after{
content: '';
width: 0;
height: 35px;
border-left: 1px solid #000;
position: absolute;
top: 2.5px;
right: 0;
}
nav a:last-child:after{
visibility: hidden;
}
ol{
border: 1px solid #000;
border-top: none;
min-height: 300px;
padding-left: 40px;
}
ol li{
line-height: 40px;
}
</style>
</head>
<body>
<div class="wrap" ng-controller="IndexController">
<nav>
<a href="#/1">摇滚</a>
<a href="#/2">民族</a>
<a href="#/3">民谣</a>
<a href="#/4">公路</a>
</nav>
<ol>
<div ng-view=""></div>
</ol>
</div>
<script src="../libs/angular.min.js"></script>
<script src="../libs/angular-route.js"></script>
<script>
var Music=angular.module('Music',['ngRoute']);
Music.config(['$routeProvider',function ($routeProvider) {
$routeProvider.when('/:id',{
templateUrl:'./list.html',
controller:'IndexController'
}).otherwise({
redirectTo:'/1'
});
}]);
Music.controller('IndexController',['$scope','$http','$routeParams',function ($scope,$http,$routeParams) {
var type=$routeParams.id;
$http({
url:'./music.php',
method:'get',
params:{id:type}
}).success(function (info) {
$scope.lists=info;
});
}]);
</script>
</body>
</html>

模板页

<li ng-repeat="list in lists track by $index">{{list.text}}</li>

php

<?php
$pid=$_GET['id'];
$list = array(
array('id'=>1, 'pid'=>2, 'text'=>'我很丑可是我很温柔'),
array('id'=>2, 'pid'=>2, 'text'=>'浦公英的约定'),
array('id'=>3, 'pid'=>2, 'text'=>'你我的约定'),
array('id'=>4, 'pid'=>3, 'text'=>'pretty boy'),
array('id'=>5, 'pid'=>3, 'text'=>'See You Again'),
array('id'=>6, 'pid'=>2, 'text'=>'甜甜的'),
array('id'=>7, 'pid'=>1, 'text'=>'再见 我的爱人'),
array('id'=>8, 'pid'=>2, 'text'=>'心中的日月'),
array('id'=>8, 'pid'=>3, 'text'=>'Let It Go'),
array('id'=>10, 'pid'=>1, 'text'=>'不要说再见'),
array('id'=>11, 'pid'=>3, 'text'=>'Rise'),
array('id'=>12, 'pid'=>2, 'text'=>'再见'),
array('id'=>13, 'pid'=>1, 'text'=>'追梦人'),
array('id'=>14, 'pid'=>2, 'text'=>'不能说的秘密'),
array('id'=>15, 'pid'=>4, 'text'=>'고속도로 로맨스'),
array('id'=>16, 'pid'=>1, 'text'=>'昨日重现'),
array('id'=>17, 'pid'=>3, 'text'=>'Love Me Like You Do'),
array('id'=>18, 'pid'=>2, 'text'=>'好久不见'),
array('id'=>19, 'pid'=>1, 'text'=>'独角戏'),
array('id'=>20, 'pid'=>2, 'text'=>'K歌之王'),
array('id'=>21, 'pid'=>1, 'text'=>'往事随风'),
array('id'=>22, 'pid'=>2, 'text'=>'光辉岁月'),
array('id'=>23, 'pid'=>3, 'text'=>'Just Like Fire'),
array('id'=>24, 'pid'=>4, 'text'=>'涙の物语'),
array('id'=>25, 'pid'=>4, 'text'=>'江南Style'),
array('id'=>26, 'pid'=>4, 'text'=>'ガラガラ'),
array('id'=>27, 'pid'=>1, 'text'=>'海阔天空'),
array('id'=>28, 'pid'=>4, 'text'=>'天空之城'),
array('id'=>29, 'pid'=>4, 'text'=>'사랑이었다'),
array('id'=>30, 'pid'=>3, 'text'=>' Good Time'),
array('id'=>31, 'pid'=>1, 'text'=>'不再犹豫'),
array('id'=>32, 'pid'=>4, 'text'=>'さよならの夏 ~コクリコ坂から~'),
array('id'=>33, 'pid'=>3, 'text'=>' Heart And Soul'),
array('id'=>34, 'pid'=>4, 'text'=>'넘버나인 '),
array('id'=>35, 'pid'=>1, 'text'=>'往事只能回味'),
array('id'=>36, 'pid'=>3, 'text'=>'Bang Bang'),
array('id'=>37, 'pid'=>4, 'text'=>'君が好きだと叫びたい'),
array('id'=>38, 'pid'=>3, 'text'=>'Same Old Love'),
array('id'=>39, 'pid'=>4, 'text'=>'君をのせて'),
array('id'=>40, 'pid'=>1, 'text'=>'恋恋风尘')
);
$result=array(); foreach($list as $key=>$value){
if($value['pid']==$pid){
$result[]=$value;
}
} echo json_encode($result); // $arr=array();
// $arr[]='a';
// $arr[]='b';
?>

Angular——单页面实例的更多相关文章

  1. Angular——单页面与路由的使用

    单页面 SPA(Single Page Application)指的是通单一页面展示所有功能,通过Ajax动态获取数据然后进行实时渲染,结合CSS3动画模仿原生App交互,然后再进行打包(使用工具把W ...

  2. 解决angular单页面页面底部跳转到新页面滚动条不在顶部的问题

    以上jquery,下面js this.router.events.subscribe((event) => { document.body.scrollTop=0; }); 另一种写法 impo ...

  3. phantomjs和angular-seo-server实现angular单页面seo

    1.下载phantomjs,并配置环境变量为   eg:E:\phantomjs-2.1.1-windows\bin 2.下载angular-seo-server 3.windows下:cmd eg: ...

  4. webpack+react+antd 单页面应用实例

    React框架已经火了好长一段时间了,再不学就out了! 对React还没有了解的同学可以看看我之前的一篇文章,可以快速简单的认识一下React.React入门最好的实例-TodoList 自己从开始 ...

  5. 基于angular的route实现单页面cnodejs

    Angular ui-router 前言 之前不太理解前端怎么实现路由功能,以前知道有一种方式使用html5的pushState可以操作url才实现路由的功能,在实践项目中也用过一次,后来这种操作叫成 ...

  6. 浅谈HTML5单页面架构(一)——requirejs + angular + angular-route

    心血来潮,打算结合实际开发的经验,浅谈一下HTML5单页面App或网页的架构. 众所周知,现在移动Webapp越来越多,例如天猫.京东.国美这些都是很好的例子.而在Webapp中,又要数单页面架构体验 ...

  7. jQuery File Upload 单页面多实例的实现

    jQuery File Upload 的 GitHub 地址:https://github.com/blueimp/jQuery-File-Upload 插件描述:jQuery File Upload ...

  8. angular(3)服务 --注入---自定义模块--单页面应用

    ng内部,一旦发生值改变操作,如$scope.m=x,就会自动轮询$digest队列,触发指定的$watch,调用其回调函数,然后修改dom树. 干货:https://github.com/xufei ...

  9. MVC route 和 Angular router 单页面的一些方式

    直接看代码和注释吧 ASP.NET MVC router public class RouteConfig { public static void RegisterRoutes(RouteColle ...

随机推荐

  1. Jenkins + SVN搭建php持续集成

    目标需求 开发提交代码到SVN,jenkins在分发服务器上执行'svn update',分发服务器在把代码同步到webserver,实现持续集成 流程 配置jenkins 一.jenkins所需插件 ...

  2. mysql 经常使用命令整理总结

    #改动字段类型 alter table `table_name` modify column ip varchar(50); #添加字段 alter table `table_name` add ip ...

  3. [翻译角]Headline English: A Captain Should Be Pitch Perfect at a Multitude of Skills (ESLPOD Blog)

    以下转自www.eslpod.com,翻译为本人添加.其余版权均归原网站所有. ESLPOD是一个英语学习网站,我最初知道这个网站,是因为“奶爸”<把你的英语用起来>(电子版3元)一书的推 ...

  4. BZOJ1179 : [Apio2009]Atm 缩点+spfa

    1179: [Apio2009]Atm Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 2069  Solved: 826[Submit][Status ...

  5. gitlab结构分析

    1 gitlab的工作流程 2

  6. mongodb配置主从模式

    Mongodb的replication主要有两种:主从和副本集(replica set).主从的原理和mysql类似,主节点记录在其上的所有操作oplog,从节点定期轮询主节点获取这些操作,然后对自己 ...

  7. lodop

    一.控件参数 Lodop有如下控件参数,以页面object对象元素的参数形式使用: Caption名称:设置控件的显示标题格式: < pa ram name="Caption" ...

  8. shell脚本执行错误:#!/bin/bash: No such file or directory

    执行.sh脚本时控制台报错 : #!/bin/bash: No such file or directory 解决办法: cat -A 文件路径 会发现第一行有问题 M-oM-;M-?#!/bin/b ...

  9. 移动前端第二弹:善用meta

    前言 在移动前端第一弹:viewport详解中,我们讲了viewport,那是一个关于meta的故事.这次我们会就将meta这个故事讲得更广阔.更有意思一些. 写过HTML的童鞋,应该都对这个不陌生, ...

  10. MARK ZUCKERBERG, A letter to our daughter(转)

    A letter to our daughter   MARK ZUCKERBERG·WEDNESDAY, DECEMBER 2, 2015   Dear Max, Your mother and I ...