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不会被 ...
随机推荐
- json学习系列(5)-json错误解析net.sf.ezmorph.bean.MorphDynaBean cannot be cast to
最近在使用json的时候,报了下面的错误: net.sf.ezmorph.bean.MorphDynaBean cannot be cast to java.lang.String 这种错误非常常见, ...
- WCF:2个常见错误
1.另一应用程序已使用 HTTP.SYS 注册了该 URL 在做WCF wsDualHttpBinding的时候,调试时会出现此异常. 其意思为:有一个Host已经启动了,占用了指定的端口了. & ...
- Edmond_Karp算法
核心思想:通过bfs不断在网络中寻找最短的增广路,从而求得最大流.时间复杂度O(VE^) 算法模板: int Edmond_Karp(int s,int t) { ; memset(flow,,siz ...
- BZOJ4068 : [Ctsc2015]app
对于一个所选任务集合,如果对于任意时刻$i$,$i$前面所选任务数都不超过i的话,那么这些任务可以全选. 维护一棵线段树$T$,第$i$个位置一开始为$i$,每使用一个任务,$[t,T]$都要减$1$ ...
- BZOJ3839 : [Pa2013]Działka
对于每个询问,首先可以通过扫描线+线段树求出四个方向的第一个点,询问范围等价于框住这些点的最小矩形. 对于一个点$i$,预处理出: $A[i][j]$:$i$往左下角按凸壳走到$j$时,凸壳上相邻两点 ...
- fireBug使用指南
据说,对于网页开发人员来说,Firebug是Firefox浏览器中最好的插件之一. 我最近就在学习怎么使用Firebug,网上找到一篇针对初学者的教程,感觉比较有用,就翻译了出来. ========= ...
- 【wikioi】1018 单词接龙
题目链接 算法:DFS+考你阅题 题目描述: 单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词,且给定一个开头的字母,要求出以这个字母开头的最长的“龙”(每个单词都最多在“龙”中 ...
- java正则表达式过滤html标签
import java.util.regex.Matcher; import java.util.regex.Pattern; /** * <p> * Title: HTML相关的正则表达 ...
- RN组件之ListView
/** * Created by DaGuo on 2016/4/7. */ 'use strict' import React,{ Component, View, Text, ListView, ...
- virsh命令
查看虚拟机: [root@super67 ~]# virsh list Id Name State --------------------- ...