angularjs: broadcast from directive to controller

后端 未结 3 1151
萌比男神i
萌比男神i 2021-01-11 12:04

Im trying to send a message from within a directive to its parent controller (without success)

Here is my HTML

3条回答
  •  星月不相逢
    2021-01-11 12:17

    To get { nr: 10 } you should add 2 arguments to listener: event and data:

    $scope.$on('go', function(event, data){ 
      alert(JSON.stringify(data));
    });
    

    (keep in mind that we use $on and not on)

    Full example in plunker

提交回复
热议问题