首页 > Web开发 > 详细

AngularJs 父子级Controller传递数据

时间:2015-12-31 10:23:18      阅读:375      评论:0      收藏:0      [点我收藏+]
<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 父子级Controller传递数据

原文:http://www.cnblogs.com/zhujiabin/p/5090808.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!