刘满博客

AngularJs 父子级Controller传递数据

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


已发布

分类

作者:

标签

评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据