ngIf equivalent for VaniallaJS


#1

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.


#2

Wrap everything inside loaded event with

if (!args.object.isCollapsed) {

}

That should work for you


#3

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


#4

@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?


#5

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


#6

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.


#7

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


#8

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.


#9

If is there anybody else who needs something like this, I wrote a small component that does just that: https://gist.github.com/surdu/57ad41764c714c86497b92e1b4cde04e