使用$ scope。$ emit和$ scope。$ on

本文翻译自:Working with $scope.$emit and $scope.$on

How can I send my $scope object from one controller to another using .$emit and .$on methods? 如何使用.$emit.$on方法将$scope对象从一个控制器发送到另一个控制器?

function firstCtrl($scope) {
    $scope.$emit('someEvent', [1,2,3]);
}

function secondCtrl($scope) {
    $scope.$on('someEvent', function(mass) { console.log(mass); });
}

It doesn't work the way I think it should. 它不像我认为的那样工作。 How do $emit and $on work? $emit$on work如何运作?


#1楼

参考:https://stackoom.com/question/yqdK/使用-scope-emit和-scope-on


#2楼

First of all, parent-child scope relation does matter. 首先,父子范围关系确实很重要。 You have two possibilities to emit some event: 你有两种可能发出一些事件:

  • $broadcast -- dispatches the event downwards to all child scopes, $broadcast - 将事件向下发送到所有子范围,
  • $emit -- dispatches the event upwards through the scope hierarchy. $emit - 通过范围层次结构向上调度事件。

I don't know anything

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值