AngularJS - $ emit only works within the current volume?

I created two directives: "Parent and child." Trying to get them to talk to each other. It seems that if they both have a scope, they do not receive events. This does not seem to be correct according to the documentation which $emitstates:Dispatches an event name upwards through the scope hierarchy notifying the registered ng.$rootScope.Scope#methods_$on listeners.

So, this should bubble in areas?

http://plnkr.co/edit/WNqN4XZKaLAvBEtSyERA?p=preview

+4
source share
2 answers

The problem is assuming parent / child:

  • Parent - this is only the parent element of the Child , but not the parent.
  • sibling scopes, $rootScope ($ id: 002) .

??

  • - this commit, Isolate scope is now available only to the isolate directive that requested it and its template.
  • , ( ) - .
  • , child , .
  • $emit, $broadcast sibling.

enter image description here


:

: http://plnkr.co/edit/EfKJthkQLitWnF2srykM?p=preview

, , .

.directive('parent', function ($timeout) {
  return {
    template:'<child name="Jimmy"></child>',

?

.

.directive('parent', function ($timeout) {
  return {
    controller: function(){
      this.hungry = function(message){
        // something
      }
    }

:

.directive('child', function ($timeout) {
  return {
    require: "^parent",
    link: function (scope, element, attrs, parentCtrl) {

       parentCtrl.hungry("I'm hungry!")
+6

, / .

, , scope: true scope: {...}. .

. plucker

+1

Source: https://habr.com/ru/post/1524039/


All Articles