基本介绍

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. Linux学习系列之MySQL备份

    MySQL排除表备份 #!/bin/bash #created by 90root #date: 20160809 date_y=$(date +%Y) date_m=$(date +%m) time ...

  2. Kafka单机Windows环境搭建

    Kafka单机Windows环境搭建 1,安装jdk1.8:安装目录不能有中文空格: 2,下载zookeeper,https://mirrors.cnnic.cn/apache/zookeeper/z ...

  3. C++ - 库函数优先级队列(priority_queue)输出最小值 代码

    库函数优先级队列(priority_queue)输出最小值 代码 本文地址: http://blog.csdn.net/caroline_wendy 库函数优先级队列(priority_queue)的 ...

  4. poj 3263 Tallest Cow(线段树)

    Language: Default Tallest Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1964   Ac ...

  5. Delphi异常处理的基本原则和方法

    Delphi异常处理的基本原则和方法 一.异常的来源. 在Delphi的应用程序中,下列的情况都比较有可能产生异常.(1)文件处理(2)内存分配(3)Windows资源(4)运行时创建对象和窗体(5) ...

  6. ubuntu安装virtualbox

    1.下载 2.sudo dpkg -i virtualbox-5.2_5.2.10-122088_Ubuntu_xenial_amd64.deb $sudo dpkg -i virtualbox-5. ...

  7. java多线程面试题(来自转载)

    在典型的Java面试中, 面试官会从线程的基本概念问起, 如:为什么你需要使用线程, 如何创建线程,用什么方式创建线程比较好(比如:继承thread类还是调用Runnable接口),然后逐渐问到并发问 ...

  8. python中如何理解if __name__ == '__main__'

    __name__ 是当前模块名,当模块被直接运行时模块名为 __main__ .这句话的意思就是,当模块被直接运行时,以下代码块将被运行,当模块是被导入时,代码块不被运行.我们通过一个简单的例子来理解 ...

  9. Java 技术体系(JDK 与 JRE 的关系)、POJO 与 JavaBeans

    Java 技术体系的分层结构(不同的颜色表示不同的层次),尤其注意 JDK 与 JRE 之间的包含关系: 图见 Java Platform Standard Edition 7 Documentati ...

  10. [Codeforces Round511C] Enlarge GCD

    [题目链接] https://codeforces.com/contest/1047/problem/C [算法] 首先求出n个数的最大公约数g , 将每个数除以g , 那么 , 问题就转化为在n个数 ...