zoukankan      html  css  js  c++  java
  • AngularJs 父子级Controller传递数据

    <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

  • 相关阅读:
    scrapy 中间件
    索引
    理解平均负载
    jquery1
    网络编程
    模块
    进程
    图书管理系统用ajax删除书籍
    mysql
    jquery
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/5090808.html
Copyright © 2011-2022 走看看