angularJS中controller的通信
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div ng-app="bb">
<div ng-controller="abx">
<ul ng-repeat="names in name track by $index">
<li ng-bind="names.names"></li>
</ul>
<button ng-click="sub()">减</button>
<span ng-bind="remark"></span> {{remark}}
<hr>
<div ng-controller="aby">
<button ng-click="add()">加</button>
<span ng-bind="remark"></span> {{remark}}
</div>
</div>
<hr>
<hr>
<div ng-view></div>
</div>
</body>
<script src="Angular.js"></script>
<script src="route.js"></script>
<script>
var app= angular.module("bb",['ngRoute']);
app.controller("abx",function($rootScope,$scope){
$scope.name=[
{names:"123"},
{names:"456"},
{names:"789"},
];
$scope.remark=100;
$scope.$on("adds",function(event,data){
$scope.remark+=data;
});
$scope.$on("subs",function(event,data){
$scope.remark-=data;
});
$scope.sub = function(){
$scope.$broadcast("subs",10);//向下广播
};
}); app.controller("aby",function ($rootScope,$scope){
$scope.remark=100;
$scope.add=function(){
$scope.$emit("adds",10);//向上广播
};
$scope.$on("adds",function(event,data){
$scope.remark+=data;
});
$scope.$on("subs",function(event,data){
$scope.remark-=data;
});
});
//路由
app.config(function ($routeProvider) {
$routeProvider.when("/index",{
controller: 'otherOneCtrl',
templateUrl: 'templete/otherOne.html',
publicAccess: true
}).when("/index2",{
controller: 'otherTwoCtrl',
templateUrl: 'templete/otherTwo.html',
publicAccess: true
}).otherwise({
redirectTo: '/index'
});
}); app.controller("otherOneCtrl",function ($scope){
$scope.other="other1";
});
app.controller("otherTwoCtrl",function ($scope){
$scope.other="other2";
});
</script>
</html>
angularJS中controller的通信的更多相关文章
- AngularJS 中 Controller 之间的通信
用 Angular 进行开发,基本上都会遇到 Controller 之间通信的问题,本文对此进行一个总结. 在 Angular 中,Controller 之间通信的方式主要有三种: 1)作用域继承.利 ...
- Angularjs中controller的三种写法
在Angular中,Directive.Service.Filter.Controller都是以工厂方法的方式给出,而工厂方法的参数名对应着该工厂方法依赖的Service.angularjs中cont ...
- AngularJS中控制器之间通信方法
在同个angular应用的控制器之间进行通信可以有很多种不同的方式,本文主要讲两种: 基于scope继承的方式和基于event传播的方式 基于scope继承的方式 最简单的让控制器之间进行通信的方法是 ...
- angularJs 中controller与sever
网上找到的一个例子,感觉对于初学者理解将controller抽成服务有帮助.主要是方便理解什么时候应该来做服务. html部分 <!DOCTYPE html> <html ng-ap ...
- angularJs中$controller的使用
$controller的使用 参考:https://stackoverflow.com/questions/27866620/can-someone-provide-a-use-case-for-th ...
- Angularjs Controller 间通信机制
在Angularjs开发一些经验总结随笔中提到我们需要按照业务却分angular controller,避免过大无所不能的上帝controller,我们把controller分离开了,但是有时候我们需 ...
- 【转】Angularjs Controller 间通信机制
在Angularjs开发一些经验总结随笔中提到我们需要按照业务却分angular controller,避免过大无所不能的上帝controller,我们把controller分离开了,但是有时候我们需 ...
- angularJS中directive与controller之间的通信
当我们在angularJS中自定义了directive之后需要和controller进行通讯的时候,是怎么样进行通讯呢? 这里介绍3种angular自定义directive与controller通信的 ...
- angularJS中directive与directive 之间的通信
上一篇讲了directive与controller之间的通信:但是我们directive与directive之间的通信呢? 当我们两个directive嵌套使用的时候怎么保证子directive不会被 ...
随机推荐
- ZOJ2930 The Worst Schedule(最小割)
题目大概说有n个任务,每个任务可以提前或推迟,提前或推迟各有一定的费用,有的任务一旦推迟另一个任务也必须推迟,问怎么安排任务使花费最少,且最少花费的条件下提前的任务数最多能多少. 问题就是要把各个任务 ...
- HDU1796 How many integers can you find(容斥原理)
题目给一个数字集合,问有多少个小于n的正整数能被集合里至少一个元素整除. 当然是容斥原理来计数了,计算1个元素组合的有几个减去2个元素组合的LCM有几个加上3个元素组合的LCM有几个.注意是LCM. ...
- python+pygame游戏开发之使用Py2exe打包游戏
最近在用python+pygame 开发游戏,写完以后在分享给朋友玩的时候遇到了很大的问题,只有搭建了环境才能运行python脚本. 这会吓退99%以上的人……所以把我们的游戏打包(注意是打包而不是编 ...
- bug 修改心得
我在做一个项目的时候,分页无法显示,于是我就开始进行各种修改. 最后我发现竟然是因为配置文件写错了,结果页面跳到别的页面, 跳转到了单项详细页面.
- TYVJ P1056 能量项链 Label:环状区间DP
做题记录:2016-08-16 20:05:27 背景 NOIP2006 提高组 第一道 描述 在Mars星球上,每个Mars人都随身佩带着一串能量项链.在项链上有N颗能量珠.能量珠是一颗有头 ...
- 【BZOJ】1862: [Zjoi2006]GameZ游戏排名系统 & 1056: [HAOI2008]排名系统(treap+非常小心)
http://www.lydsy.com/JudgeOnline/problem.php?id=1862 http://www.lydsy.com/JudgeOnline/problem.php?id ...
- 【TYVJ】1982 武器分配(费用流)
http://tyvj.cn/Problem_Show.aspx?id=1982 一眼题.. 源向每个人连容量为1,费用为0的边. 每个人向一个中转节点na连容量1,费用0的边(你也可以不连,直接连后 ...
- 【wikioi】1029 遍历问题
题目链接:http://www.wikioi.com/problem/1029/ 算法:数学 本题有个2小技巧. 一棵二叉树的前序遍历a1a2a3...ai和后序遍历b1b2b3...bi有一种关系: ...
- (转)微信公众平台开发之基于百度 BAE3.0 的开发环境搭建(采用 Baidu Eclipse)
原文传送门(http://blog.csdn.net/bingtianxuelong/article/details/17843111) 版本说明: V1: 2014-2-13 ...
- Vim 学习资料
VIM中文手册 简明 Vim 练级攻略 所需即所获:像 IDE 一样使用 vim