AngularJs 父子级Controller传递数据
2015-12-31 09:58
651 查看
<div ng-controller="MyAccountCtrl"> <div ng-controller="TransferCtrl"> ............. </div> </div>
// 子级传递数据给父级 // 子级传递 $scope.checkLoggedIn = function(type) { $scope.transferType = type; $scope.$emit('transfer.type', type); } // 父级接收 $scope.$on('transfer.type', function(event, data) { $scope.transferType = data; }); $scope.checkLoggedIn = function() { var type = $scope.transferType; }
// 父级传递数据给子级 // 父级传递 $scope.transferType = ''; $scope.checkLoggedIn = function(type) { $scope.transferType = type; $scope.$broadcast('transfer.type', type); } // 子级接收 $scope.transferType = ''; $scope.$on('transfer.type', function(event, data) { $scope.transferType = data; }); $scope.checkLoggedIn = function() { var type = $scope.transferType; }
在线实例:http://each.sinaapp.com/angular/apps/app-broadcast.html
相关文章推荐
- AngularJS 学习笔记值post传值
- 《AngularJS深度剖析与最佳实践》简介
- AngularJS中实现显示或隐藏动画效果的方式总结
- 开启AngularJS学习之旅
- angularjs
- 关于angularJS绑定数据时自动转义html标签
- [Angularjs]angular ng-repeat与js特效加载先后导致的问题
- angularjs指令中的replace与transclude参数
- AngularJS基础——工具方法
- angularjs指令link函数参数scope,指令controller依赖注入的$scope,与指令外部controller的$scope的关系
- AngularJS 使用 even 和 odd 表格
- AngularJS 使用序号的表格
- AngularJS 使用 uppercase 过滤器的表格
- 关于 angular 小心得
- AngularJS表格排序
- AngularJS 表格(带有CSS样式)
- AngularJS显示一个简单表格
- angularJS 实例
- AngularJS Remote validation
- AngularJS validation with messages