$ emit event does not work with ng-if

I had a new requirement for implementation, so I had to display the directive based on the condition.

<div ng-app="myApp">

  <body-dir>

    <icon-dir> 
    </icon-dir>

    <filter-dir>
     </filter-dir>

    <widget-dir ng-if="someCondition">
    </widget-dir>

  </body-dir>
</div>

From the structure of the directive above, I am trying to do 'widget-dir'based on a property someCondition.

The point is that I am emitting an event from <filter-dir>and catching an event in widget-dirthat does not work.

If I remove ng if it works fine.

Below I understood from various sources:

  • ng - when creating a new area. But according to angular doc, the newly created region inherits from the parent.

    So, should he share the area body-dir? If it is shared, then what we emit the event from <filter-dir>should get into widget-dir?

ng-if. , .

, $emit , . , ( ?).

:. , , ng-if ( ), . ng-if . , angular ng-if.

angular.module('app').directive('widgetDir', function(){
  return {
    template: '<br><span ng-if="true">I\'m in "ng-if"</span>',
    link: function(scope, element, attrs){
  scope.$on('evt-filter', function(evt, data){
    alert(data);
  });
    }
  }
})

-, , .

+4
1

1: , DOM, . ng-show, .

2:

$, $emit :

$rootScope. $broadcast ('PHOTO_UPLOADED', );

$rootScope. $on ('PHOTO_UPLOADED', (, ) {          thumbnail = ;       });

0

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


All Articles