HTML代码

<div ng-controller="MyAccountCtrl">  
  
   <div ng-controller="TransferCtrl">  
           .............  
  
   </div>  
  
</div>  

js代码

// 子级传递数据给父级  
// 子级传递  
$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;  
} 

js代码

// 父级传递数据给子级  
// 父级传递  
$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;  
}  

应用实例:未读消息的个数显示

    子级控制器js代码:

 1 $scope.messageView = function(data){
 2             $scope.currentMessage = data;
 3             ngDialog.open({
 4                 template: 'html/admin/messageView.html',
 5                 className: 'ngdialog-theme-plain custom-width-70',
 6                 scope: $scope,
 7                 cache: false,
 8                 controller: function(){
 9                     if(data.readStatus == 0){   //状态为0表示未读;
10                         $scope.$emit('messageCount', true);  //等于0的时候触发
11                     }
12                 }
13             });
14             if (data.readStatus == 1) return;
15             data.readStatus = 1;
16             $http.post($scope.URL + "message/updateMessage", data).success(function(){
17                 $scope.load();
18             });
19         };
View Code

相关文章:

  • 2021-09-21
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2021-11-24
  • 2022-12-23
  • 2021-10-05
猜你喜欢
  • 2022-12-23
  • 2021-04-21
  • 2021-12-25
  • 2021-07-13
  • 2022-12-23
  • 2021-12-03
相关资源
相似解决方案