ngIf equivalent for VaniallaJS


In Angular + NS, if I have an element that has the ngIf attribute and loaded event, the loaded event of that element will not be called until the ngIf expression evaluates to true.

Is there something similar for VanillaJS + NS ? The only visual equivalent I know of is the visibility attribute, but the loaded event will be called for all elements, regardless of their visibility value.


Wrap everything inside loaded event with

if (!args.object.isCollapsed) {


That should work for you


@multishiv19 But the loaded event will not be called again when the visibility changes, so this is not really a solution for me :frowning:


@surdu So you want some loaded event to be called EVERY time when the item is visible?
is that the functionality you are looking for?


@multishiv19 Yes. As far as I can tell, this is how ngif works.


I don’t see any straightforward way to do that.
You can use a property change listener to listen for change in visibility,
and perform some actions on the View that you want to toggle.


Just created a playground example just to make sure that ngIf will repeat the loaded event after each show, and it does.


ngIf basically doesn’t show / hide content, it never creates one if condition hasn’t met. I don’t think there is something similar in {N} core, so you have handle conditions, adding / removing the component back form JavaScript to get similar experience.


If is there anybody else who needs something like this, I wrote a small component that does just that: