angularjs1-路由
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="angular.min.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular-sanitize.min.js"></script>
<style>
.red{ background:red;}
.yellow{ background:yellow;}
</style>
</head>
<body>
<div ng-app="myApp">
<div ng-controller="firstController">
<div ng-bind-html="text"></div>
</div>
</div>
<script type="text/javascript">
var app = angular.module('myApp',['ngSanitize']);//依赖
app.controller('firstController',['$scope','$interval',function($scope,$interval){
$scope.text = '<h1>hello</h1>';//解析html,
}]);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="angular.min.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.2.9/angular-route.min.js"></script>
</head>
<body>
<div ng-app="myApp">
<div class="header">
<a href="#div1">第一个div</a>
<a href="#div2">第二个div</a>
<a href="#div3">第三个div</a>
<a href="#content/13/5">点击去内容12</a>
</div>
<div ng-view></div>
</div>
<script type="text/javascript">
var app = angular.module("myApp", ['ngRoute']);
app.run(['$rootScope',function($rootScope){
$rootScope.$on('$routeChangeStart',function(event,current,pre){
console.log(event);
// console.log(current);
// console.log(pre);
});
}]);
app.config(['$routeProvider',function($routeProvider){
$routeProvider
.when('/div1',{
templateUrl : '../template1.html',
controller : 'div1Controller'
})
.when('/div2',{
template : '<p>这是div2{{text}}</p>',
controller : 'div2Controller'
})
.when('/div3',{
template : '<p>这是div3{{text}}</p>',
controller : 'div3Controller'
})
.when('/content/:id/:cateid',{
template : '<p>这是content{{id}}</p>',
controller : 'div4Controller'
})
.otherwise({
redirectTo : '/div3'
});
}]); app.controller('div1Controller',function($scope){
$scope.text='phonegap中文网 外部页面';
});
app.controller('div2Controller',function($scope){
$scope.text='div2Controller';
});
app.controller('div3Controller',function($scope){
$scope.text='div3Controller';
});
app.controller('div4Controller',['$scope','$routeParams',function($scope,$routeParams){
console.log($routeParams);
$scope.id=$routeParams.num;
$scope.text='div4Controller';
}]);
/*
* app.controller('firstController',function($scope){
//$scope.text='phonegap中文网';
});
* */
</script>
</body>
</html>
<!DOCTYPE HTML>
<html ng-app="myApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script src="angular.min.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.2.9/angular-route.min.js"></script>
<script>
var m1 = angular.module('myApp',['ngRoute']);
m1.config(['$routeProvider',function($routeProvider){
$routeProvider
.when('/aaa/:num',{
template : '<p>首页的内容</p>{{name}}',
controller : 'Aaa'
})
.when('/bbb',{
template : '<p>学员的内容</p>{{name}}',
controller : 'Bbb'
})
.when('/ccc',{
templateUrl : 'test.html',
controller : 'Ccc'
})
.otherwise({
redirectTo : '/aaa'
});
}]);
m1.run(['$rootScope',function($rootScope){//run是module初始化的时候,
$rootScope.$on('$routeChangeStart',function(event,current,pre){//on监听触发的事件,
console.log(event);
console.log(current);
console.log(pre);
});
}]);
m1.controller('Aaa',['$scope','$location','$routeParams',function($scope,$location,$routeParams){
$scope.name = 'hello';
$scope.$location = $location;
console.log( $routeParams );
}]);
m1.controller('Bbb',['$scope',function($scope){
$scope.name = 'hi';
}]);
m1.controller('Ccc',['$scope',function($scope){
$scope.name = '你好';
}]);
</script>
</head>
<body>
<div ng-controller="Aaa">
<a href="" ng-click="$location.path('aaa/123')">首页</a>
<a href="" ng-click="$location.path('bbb')">学员</a>
<a href="" ng-click="$location.path('ccc')">课程</a>
<div ng-view></div>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="angular.min.js"></script>
<script src="http://cdn.bootcss.com/angular.js/1.2.9/angular-route.min.js"></script>
</head>
<body>
<div ng-app="myApp">
<div class="header" ng-controller="firstController">
<a ng-click="$location.path('div1')">第一个div</a>
<a ng-click="$location.path('/div2')">第二个div</a>
<a href="#div3">第三个div</a>
<a href="#content/13/5">点击去内容12</a>
</div>
<div ng-view></div>
</div>
<script type="text/javascript">
var app = angular.module("myApp", ['ngRoute']);
app.run(['$rootScope',function($rootScope){
$rootScope.$on('$routeChangeStart',function(event,current,pre){
console.log(event);
// console.log(current);
// console.log(pre);
});
}]);
app.config(['$routeProvider',function($routeProvider){
$routeProvider
.when('/div1',{
templateUrl : 'template1.html',
controller : 'div1Controller'
})
.when('/div2',{
template : '<p>这是div2{{text}}</p>',
controller : 'div2Controller'
})
.when('/div3',{
template : '<p>这是div3{{text}}</p>',
controller : 'div3Controller'
})
.when('/content/:id/:cateid',{
template : '<p>这是content{{id}}</p>',
controller : 'div4Controller'
})
.otherwise({
redirectTo : '/div1'
});
}]);
app.controller('div1Controller',function($scope){
$scope.text='phonegap中文网 外部页面';
});
app.controller('div2Controller',function($scope){
$scope.text='div2Controller';
});
app.controller('div3Controller',function($scope){
$scope.text='div3Controller';
});
app.controller('div4Controller',['$scope','$routeParams',function($scope,$routeParams){
console.log($routeParams);
$scope.id=$routeParams.num;
$scope.text='div4Controller';
}]);
app.controller('firstController',function($scope,$location){
$scope.$location= $location;
$scope.text='phonegap中文网';
});
</script> </body>
</html>
angularjs1-路由的更多相关文章
- AngularJS1.6版本中ui-router路由中/#!/的解决方法 - zhuan
本地编译出的文件可以正常运行,但是服务器编译后到了测试那里路由上就莫名的出现了/#!/,这导致了很多问题. 后来查了下是服务器编译器把AngularJS升级到了1.6版本,而我本地的依旧是1.5. 但 ...
- AngularJs1.X学习--路由
[三种使用说明:] $stateProvider.state('station.printQRCode', { //params: { 'parentOfficeId': null }, //一次性参 ...
- AngularJS-chapter2-7-前端路由
Form表单提交会导致页面之间的切换,没法实现单页应用 Ajax请求不会留下History记录(在后台管理系统,没有后台历史记录还可以) ,但在网络型应用或门户型应用(用户没有办法给改页面加标签或分享 ...
- javascript基础修炼(6)——前端路由的基本原理
[造轮子]是笔者学习和理解一些较复杂的代码结构时的常用方法,它很慢,但是效果却胜过你读十几篇相关的文章.为已知的API方法自行编写实现,遇到自己无法复现的部分再有针对性地去查资料,最后当你再去学习官方 ...
- AngularJS1.X版本基础
AngularJS 知识点: DataBinding Providers Validators Directives Controllers Modules Expressions Factori ...
- Angular2入门系列教程6-路由(二)-使用多层级路由并在在路由中传递复杂参数
上一篇:Angular2入门系列教程5-路由(一)-使用简单的路由并在在路由中传递参数 之前介绍了简单的路由以及传参,这篇文章我们将要学习复杂一些的路由以及传递其他附加参数.一个好的路由系统可以使我们 ...
- Angular2入门系列教程5-路由(一)-使用简单的路由并在在路由中传递参数
上一篇:Angular2入门系列教程-服务 上一篇文章我们将Angular2的数据服务分离出来,学习了Angular2的依赖注入,这篇文章我们将要学习Angualr2的路由 为了编写样式方便,我们这篇 ...
- nodejs进阶(3)—路由处理
1. url.parse(url)解析 该方法将一个URL字符串转换成对象并返回. url.parse(urlStr, [parseQueryString], [slashesDenoteHost]) ...
- .NetCore MVC中的路由(2)在路由中使用约束
p { margin-bottom: 0.25cm; direction: ltr; color: #000000; line-height: 120%; orphans: 2; widows: 2 ...
- .NetCore MVC中的路由(1)路由配置基础
.NetCore MVC中的路由(1)路由配置基础 0x00 路由在MVC中起到的作用 前段时间一直忙于别的事情,终于搞定了继续学习.NetCore.这次学习的主题是MVC中的路由.路由是所有MVC框 ...
随机推荐
- mysql 强制修改密码
mysql忘记密码时强制修改步骤如下: 1.用命令编辑配置文件/etc/my.cnf 2.添加一条语句使其变为不用密码就能进入的状态 skip-grant-tables 3.保存并退出,然后再命令行输 ...
- Super超级ERP系统---(4)采购管理--采购单创建
Erp系统中采购是系统必不可少的一部分,也就是ERP种的进货模块,超级ERP系统中的采购模块选选择采购供应商,然后选择进货商品的数量和采购价格,创建采购进货单 1.创建采购单 2.审核采购单 采购单创 ...
- markdown 计算器
计算器 分四种运算(加减乘除).括号.去除最后括号.验证等式是否计算完成 bracket = re.compile(r'\([^()]+\)') # 找括号 multiplys = re.compil ...
- 自定义typecho后台路径
如何自定义后台路径 Typecho 安装好后,默认的后台路径是 domain.com/admin/,为了提高安全性,我们允许以 domain.com/xxxx/ 的方式访问,其中 xxxx 是你自定义 ...
- RabbitMQ学习之基于spring-rabbitmq的RPC远程调用
http://blog.csdn.net/zhu_tianwei/article/details/40920985 spring-rabbitmq中实现远程接口调用,主要在com.rabbitmq.s ...
- PHP中each与list用法分析
1.each的用法 先看API array each ( array &$array ) api里是这么描述的:each — 返回数组中当前的键/值对并将数组指针向前移动一步 我们先来看看返回 ...
- Integer Intervals POJ - 1716_查分约束_
Code: #include<cstdio> #include<queue> #include<algorithm> using namespace std; co ...
- Codeforces Round #447 (Div. 2)E. Ralph and Mushrooms
Ralph is going to collect mushrooms in the Mushroom Forest. There are m directed paths connecting n ...
- ClipboardJS实现点击复制功能
<script src="//lib.baomitu.com/clipboard.js/1.7.1/clipboard.min.js"></script> ...
- Project Euler 30 Digit fifth powers
题意:判断一个数 N 的每一位的5次方的和是否为其本身 ,求出所有满足条件的数的和 思路:首先设这个数 N 为 n 位,可以简单的判断一下这个问题的上界 10 ^ n <= 9 ^ 5 × n, ...