Adding a class programatically


#1

I’m doing this:

absoluteLayout.className = "dropCategory";
const lbl = new Label();
lbl.text = `drop${i}`;
absoluteLayout.addChild(lbl);
this.cl.addChild(absoluteLayout);

The layout gets added with the label. The className gets added, but the styles are not picked up. Isn’t this the proper way to add class to a programmatically added element?

Here is what the added element looks like in the debugger:

<AbsoluteLayout effectiveTop="0" top="0" className="dropCategory">
    <Label text="drop0"></Label>
</AbsoluteLayout>

If I create the element manually in the template and use class instead of className I see the styles applied to the element. It only does’t apply styles when I do this in the code behind.


#2

Where you have the style definition for dropCategory, in the page level CSS file or in app level CSS file?


#3

Ah, I had it in the component level css. If I move it up the tree, I see it picks it up. Thanks