Skip to content
Advertisement

Can I use something similar to Angular’s *ngFor in pyscript?

I am playing with Pyscript for the first time and I am trying to create a DOM element for each element in an array, similar to the *ngFor directive in Angular. Is there any way to achieve this?

<body>
    <div id="test"></div>
    <py-script> 
dataSet = [1,2,3,4]

for i,x in enumerate(dataSet):
    pyscript.write("test", x)
    </py-script>
</body>

Advertisement

Answer

I am trying to create a DOM element for each element in an array

To append a new DOM element, use the append=True parameter

pyscript.write("test", x, append=True)

The signature for pyscript.write

@staticmethod
def write(element_id, value, append=False, exec_id=0):

Source for pyscript.write link

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement